Pomoc w kodzie Światła - lukiwolow - 29-11-2021
Cześć,
Zrobiłem najprostsze swiatła drogowe(uliczne).
Taśma led ws2812B, 3 szt led.
Program zaczyna sie od zielonego swiatła, przyciskiem odpalamy pętle.
Wszystko chodzi ładnie, tak jak chce.
Chciałbym dodać ze po zakończonym pogramie (ponowane zapalenie się samego zielonego światła) ponownie bedzie trzeba odpalic pętle z przycisku. Niestety nie wiem jak to ogarnąc z góry dzieki
Kod: #include <ezButton.h>
#include <FastLED.h>
#define LED_TYPE WS2812B
#define DATA_PIN 2
#define NUM_LEDS 3
#define BRIGHTNESS = 0.1;
CRGB leds[NUM_LEDS];
ezButton button(4); // create ezButton object that attach to pin 7;
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, GRB>(leds, NUM_LEDS);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
while (!button.isPressed())
button.loop(); // MUST call the loop() function first
}
void loop()
{
leds[2] = CRGB(0, 15, 0);
FastLED.show();
delay(2000);
leds[1] = CRGB(15, 15, 0);
FastLED.show();
delay(2000);
leds[2] = CRGB(0, 0, 0);
FastLED.show();
leds[1] = CRGB(0, 0, 0);
FastLED.show();
leds[0] = CRGB(15, 0, 0);
FastLED.show();
delay(3000);
leds[1] = CRGB(15, 15, 0);
delay(500);
FastLED.show();
delay(2000);
leds[0] = CRGB(0, 0, 0);
leds[1] = CRGB(0, 0, 0);
FastLED.show();
leds[2] = CRGB(0, 15, 0);
FastLED.show();
delay(1000);
FastLED.show();
}
RE: Pomoc w kodzie ŚwiAtła - Jarewa0606 - 29-11-2021
Tak na szybko
Kod: #include <ezButton.h>
#include <FastLED.h>
#define LED_TYPE WS2812B
#define DATA_PIN 2
#define NUM_LEDS 3
#define BRIGHTNESS = 0.1;
CRGB leds[NUM_LEDS];
ezButton button(4); // create ezButton object that attach to pin 7;
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, GRB>(leds, NUM_LEDS);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
while (!button.isPressed())
button.loop(); // MUST call the loop() function first
}
void loop()
{
button.loop(); // MUST call the loop() function first
int btnState = button.getState();
if(btnState){
leds[2] = CRGB(0, 15, 0);
FastLED.show();
delay(2000);
leds[1] = CRGB(15, 15, 0);
FastLED.show();
delay(2000);
leds[2] = CRGB(0, 0, 0);
FastLED.show();
leds[1] = CRGB(0, 0, 0);
FastLED.show();
leds[0] = CRGB(15, 0, 0);
FastLED.show();
delay(3000);
leds[1] = CRGB(15, 15, 0);
delay(500);
FastLED.show();
delay(2000);
leds[0] = CRGB(0, 0, 0);
leds[1] = CRGB(0, 0, 0);
FastLED.show();
leds[2] = CRGB(0, 15, 0);
FastLED.show();
delay(1000);
FastLED.show();
}
}
RE: Pomoc w kodzie ŚwiAtła - lukiwolow - 30-11-2021
(29-11-2021, 23:18)Jarewa0606 napisał(a): Tak na szybko
Kod: #include <ezButton.h>
#include <FastLED.h>
#define LED_TYPE WS2812B
#define DATA_PIN 2
#define NUM_LEDS 3
#define BRIGHTNESS = 0.1;
CRGB leds[NUM_LEDS];
ezButton button(4); // create ezButton object that attach to pin 7;
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, GRB>(leds, NUM_LEDS);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
while (!button.isPressed())
button.loop(); // MUST call the loop() function first
}
void loop()
{
button.loop(); // MUST call the loop() function first
int btnState = button.getState();
if(btnState){
leds[2] = CRGB(0, 15, 0);
FastLED.show();
delay(2000);
leds[1] = CRGB(15, 15, 0);
FastLED.show();
delay(2000);
leds[2] = CRGB(0, 0, 0);
FastLED.show();
leds[1] = CRGB(0, 0, 0);
FastLED.show();
leds[0] = CRGB(15, 0, 0);
FastLED.show();
delay(3000);
leds[1] = CRGB(15, 15, 0);
delay(500);
FastLED.show();
delay(2000);
leds[0] = CRGB(0, 0, 0);
leds[1] = CRGB(0, 0, 0);
FastLED.show();
leds[2] = CRGB(0, 15, 0);
FastLED.show();
delay(1000);
FastLED.show();
}
}
Dzieki, ale nadal nie działa. Nadal robi pętle i nie wymaga ponownego wcisniecia przycisku
Pomoc w kodzie ŚwiAtła - MadMrQ - 01-12-2021
btnState jest na HIGH jeżeli przycisk nie jest wciśnięty, a na LOW jeżeli jest wciśnięty.
Osobiście napisałbym if(btnState == LOW).
Wysłane z mojego POCOPHONE F1 przy użyciu Tapatalka
RE: Pomoc w kodzie ŚwiAtła - Jarewa0606 - 01-12-2021
Fakt nie zauwazylem
Można jeszcze
if(button.isPressed())
Serial.println("The button is pressed");
if(button.isReleased())
Serial.println("The button is released");
|