control par lib button

master
JbLb 4 years ago
parent 912f987fcf
commit 2378bf05ff

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

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