Created
November 23, 2020 07:34
-
-
Save akirayou/d91ed55843fe93ff1a6648079735cffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#define FASTLED_ALLOW_INTERRUPTS 0 | |
#define FASTLED_ESP32_I2S 1 | |
#include <M5Atom.h> | |
#define HANA_PIN 22 | |
#define LED_PIN 25 | |
#define COLOR_ORDER RGB | |
#define CHIPSET WS2812 | |
#define N_LEDS 10 | |
#define BRIGHTNESS 250 | |
CRGB leds[N_LEDS]; | |
void setup() { | |
M5.begin(false, false, false); | |
Serial.begin(115200); | |
pinMode(HANA_PIN,INPUT); | |
delay(50); | |
// put your setup code here, to run once: | |
FastLED.addLeds<WS2812B,LED_PIN>(leds, N_LEDS); | |
FastLED.setBrightness( BRIGHTNESS ); | |
Serial.println("setup ---end"); | |
} | |
bool oldOut=true; | |
int count=0; | |
void loop() { | |
// put your main code here, to run repeatedly: | |
CHSV hsv; | |
CRGB rgb; | |
hsv.h=150; | |
hsv.s=200; | |
static float phase=0; | |
bool out=true; | |
#define COUNT_MAX 50 | |
out=digitalRead(HANA_PIN); | |
if(out!=oldOut)count=COUNT_MAX; | |
if(count ){ | |
phase += (oldOut)?-0.2:0.2; | |
hsv.h=(oldOut)?100:20; | |
}else{ | |
phase += out?-0.2:0.2; | |
hsv.h=(out)?100:20; | |
} | |
for(int i=0;i<N_LEDS/2;i++){ | |
float v = sin(i*1+phase); | |
if(v<0)v=0; | |
v*= (float)(COUNT_MAX-count)/COUNT_MAX ; | |
if(!out)v*=0.5; | |
hsv.v=240*v; | |
//Serial.println(hsv.v); | |
hsv2rgb_rainbow(hsv,rgb); | |
leds[N_LEDS/2-1-i]=rgb; | |
leds[N_LEDS/2+i]=rgb; | |
} | |
if(count)count--; | |
oldOut=out; | |
FastLED.show(); | |
FastLED.delay(10); | |
M5.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment