control par lib button

master
JbLb 4 years ago
parent 912f987fcf
commit 2378bf05ff

@ -14,14 +14,14 @@ board = attiny85
framework = arduino framework = arduino
lib_deps = lib_deps =
fastled/FastLED @ ^3.3.3 fastled/FastLED @ ^3.3.3
; upload by USBasp stick davidepalladino/Button-Arduino@^1.2.0
upload_protocol = custom upload_protocol = custom
upload_flags = upload_flags =
-C -C
${platformio.packages_dir}/tool-avrdude/avrdude.conf ${platformio.packages_dir}/tool-avrdude/avrdude.conf
-p -p
t85 t85
-Pusb -Pusb
-c -c
usbasp usbasp
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

@ -1,75 +1,92 @@
#include <FastLED.h> #include <FastLED.h>
#include <Button.h>
// How many leds in your strip? // How many leds in your strip?
#define BRIGHTNESS 96 #define BRIGHTNESS 96
#define NUM_LEDS 12 #define NUM_LEDS 12
#define TEMPO 100 #define TEMPO 100
#define DATA_PIN 0 #define DATA_PIN 0 // led pin
#define BTN_PIN 3 // button pin
CRGB leds[NUM_LEDS]; CRGB leds[NUM_LEDS];
float tcount = 0.0; //-INC VAR FOR SIN LOOPS float tcount = 0.0; //-INC VAR FOR SIN LOOPS
int ibright = 0; //-BRIGHTNESS (0-255) int ibright = 0; //-BRIGHTNESS (0-255)
int tempo_anim = TEMPO; int tempo_anim = TEMPO;
uint8_t gHue = 0; // rotating "base color" uint8_t gHue = 0; // rotating "base color"
void colorWipe_up (struct CRGB rgb, uint8_t wait) { Button button1(BTN_PIN, PULLUP, 5000);
for (int i=0; i < NUM_LEDS; i++) {
leds[i]=rgb; void colorWipe_up(struct CRGB rgb, uint8_t wait)
{
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = rgb;
FastSPI_LED.show(); FastSPI_LED.show();
delay(wait); delay(wait);
} }
} }
void colorWipe_down (struct CRGB rgb, uint8_t wait) {
for (int i = NUM_LEDS-1 ; i >= 0; i--) { void colorWipe_down(struct CRGB rgb, uint8_t wait)
leds[i]=rgb; {
for (int i = NUM_LEDS - 1; i >= 0; i--) {
leds[i] = rgb;
FastSPI_LED.show(); FastSPI_LED.show();
delay(wait); delay(wait);
} }
} }
void black_out(){
// all leds off void black_out()
memset(leds, 0, NUM_LEDS * 3); // all leds off {
FastSPI_LED.show(); // all leds off
} memset(leds, 0, NUM_LEDS * 3); // all leds off
void dual_color(struct CRGB color1, struct CRGB color2,uint8_t wait) {
for (int i=0; i < NUM_LEDS; i++) {
memset(leds, 0, NUM_LEDS * 3); // all leds off
leds[i]=color1;
leds[NUM_LEDS-(i+1)]=color2;
FastSPI_LED.show(); FastSPI_LED.show();
delay(wait);
}
} }
void setup() { void dual_color(struct CRGB color1, struct CRGB color2, uint8_t wait)
// put your setup code here, to run once: {
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); for (int i = 0; i < NUM_LEDS; i++) {
FastLED.setBrightness(BRIGHTNESS); memset(leds, 0, NUM_LEDS * 3); // all leds off
leds[i] = color1;
leds[NUM_LEDS - (i + 1)] = color2;
FastSPI_LED.show();
delay(wait);
}
} }
void loop() {
// put your main code here, to run repeatedly:
colorWipe_up ( CRGB::Red,tempo_anim); void setup()
delay(100); {
colorWipe_down ( CRGB::Green,tempo_anim); // put your setup code here, to run once:
delay(100); FastLED.addLeds < WS2812B, DATA_PIN, GRB > (leds, NUM_LEDS);
colorWipe_up ( CRGB::Purple,tempo_anim); FastLED.setBrightness(BRIGHTNESS);
delay(100); }
colorWipe_down ( CRGB::Blue,tempo_anim);
delay(100); void loop()
colorWipe_up ( CRGB::Black,tempo_anim); {
delay(100);
// put your main code here, to run repeatedly:
for (int i = 0; i < 10; i++) {
colorWipe_up(CRGB::Red, tempo_anim);
delay(100);
colorWipe_up(CRGB::Green, tempo_anim);
delay(tempo_anim);
}
//dual_color( CRGB::LightGreen,CRGB::Aqua,tempo_anim); //dual_color( CRGB::LightGreen,CRGB::Aqua,tempo_anim);
// dual_color( CRGB::Aqua,CRGB::LightGreen,tempo_anim); // dual_color( CRGB::Aqua,CRGB::LightGreen,tempo_anim);
dual_color( CRGB::AliceBlue,CRGB::OrangeRed,tempo_anim); for (int i = 0; i < 10; i++) {
dual_color( CRGB::AliceBlue,CRGB::OrangeRed,tempo_anim); dual_color(CRGB::Red, CRGB::Green, tempo_anim);
// dual_color( CRGB::Green,CRGB::Red,tempo_anim);
}
black_out(); black_out();
delay(100); delay(tempo_anim);
} if (button1.checkPress() == 1) {
void (); // Serial.println("SHORT PRESS!");
} else if (button1.checkPress() == -1) {
void (); // Serial.println("LONG PRESS!");
}
}

Loading…
Cancel
Save