Ingo Lohs
Published © GPL3+

Grove - Introduction in a Button & LED String Light

Beginner-Example - I bet Beginners will smile after project - sent me an selfie!

BeginnerProtip1 hour4,412
Grove - Introduction in a Button & LED String Light

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Seeed Studio Grove Base Shield
×1
Seeed Studio Grove LED String Light
×1
Seeed Studio Grove Universal Jumper
×1
Seeed Studio Grove Button
×1
Seeed Studio analog LED Strip
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Soldering is an option if you change the LED Strip - Original code works without soldering!

Story

Read more

Code

LED String Light - Example with button

C/C++
//Turns on and off a analog led string connected to digital pin 7, when pressing a button attached to pin 2.

// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int pushButton = 7;    // Button auf D7 
int x = 1;
// variables will change:
int pushButtonState = 0;     // Statusabfrage vom Button
int oldButtonState = LOW;

void setup() {
    pinMode(buttonPin, INPUT_PULLUP);   // declare Button as input
}

void loop(){
    // Get the current state of the button
  int newButtonState = digitalRead(buttonPin);

  // Has the button gone high since we last read it?
  if (newButtonState == HIGH && oldButtonState == LOW) {

    if (x == 0) {
      // Toggle on
      digitalWrite(pushButton, HIGH);
      x = 1;

    } else {
      // Toggle off
      digitalWrite(pushButton, LOW);
      x = 0;
    }
  }

  // Store the button's state so we can tell if it's changed next time round
  oldButtonState = newButtonState;
}

Credits

Ingo Lohs

Ingo Lohs

182 projects • 194 followers
I am well over 50 years and come from the middle of Germany.

Comments