Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int BUTTON_PIN = 7;
- const int LED_PIN = 3;
- #include <FastLED.h>
- #define num_leds 16
- #define pin 6
- CRGB leds[num_leds];
- int ledState = LOW;
- int lastButtonState;
- int currentButtonState;
- void setup() {
- Serial.begin(9600);
- pinMode(BUTTON_PIN, INPUT);
- pinMode(LED_PIN, OUTPUT);
- FastLED.addLeds<WS2812B, pin, GRB>(leds, num_leds);
- FastLED.setBrightness(0);
- currentButtonState = digitalRead(BUTTON_PIN);
- }
- void loop() {
- lastButtonState = currentButtonState;
- currentButtonState = digitalRead(BUTTON_PIN);
- if(lastButtonState == HIGH && currentButtonState == LOW) {
- Serial.print("The button is pressed: ");
- if(ledState == LOW) {
- ledState = HIGH;
- Serial.println("Turning LED on");
- leds[(16)] = CRGB(255, 0, 0); //this is where i lose confidence in what I have done
- FastLED.setBrightness(100);
- }
- else {
- ledState = LOW;
- Serial.println("Turning LED off");
- leds[(50)] = CRGB(0, 0, 0);
- FastLED.setBrightness(0);
- }
- digitalWrite(LED_PIN, ledState);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment