3D model · Thingiverse

Hydrate Reminder

Model details

Platform
Thingiverse
Price
Free
License
CC-BY
Print, modify and use commercially — credit the author.
  • 0 Likes
  • 43 Downloads
  • 0 Makes
  • 0 Collected
  • 0 Comments
  • 117 Views

Author:MartinKokorec25

Published

Description

Made in Arduino Changes color from green to red gradually when the button is pressed down by the bottle (30 min.) esp8266 and Adafruit_Neopixel needed (arduino extensions)

Code:

include <Adafruit_NeoPixel.h>

define PIN D6 // Pin pro připojení LED pásky define NUM_LEDS 24 // Počet LED diod v pásku int buttonPin = D2; // nastavení pinu pro tlačítko int buttonState = 0; // proměnná pro uložení stavu tlačítka

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() { pixels.begin(); // Inicializace LED pásky pinMode(buttonPin, INPUT); // nastavení pinu pro tlačítko jako vstup Serial.begin(9600); }

void loop() { // Přechod z zelené na červenou barvu for (float i = 0; i < 1; i += 0.01) { for (int j = 0; j < NUM_LEDS; j++) { int green = (1-i)*255; int red = i*255;

pixels.setPixelColor(j, pixels.Color(red, green, 0)); // Nastavení barev pomocí lineární interpolace }

pixels.show(); // Zobrazení změn na LED diodách delay(18000); // 20ms prodleva Serial.write("s");

if (digitalRead(buttonPin) == HIGH) { i = 0; Serial.write("button"); }

}

// Prodleva na červené barvě

do {delay(1); buttonState = digitalRead(buttonPin);Serial.println("stop");} while (buttonState == LOW);

// Přechod z červené na zelenou barvu for (float i = 1; i > 0; i -= 0.01) { for (int j = 0; j < NUM_LEDS; j++) { int green = (1-i)*255; int red = i*255; pixels.setPixelColor(j, pixels.Color(red, green, 0)); // Nastavení barev pomocí lineární interpolace } pixels.show(); // Zobrazení změn na LED diodách delay(20); // 20ms prodleva }

// Prodleva na zelené barvě

}

Comments 0

Loading comments…

More like this

Similar models

Names are used only to indicate the source of a result. Polyzon is not affiliated with the listed sites.