LED and BUTTON
1. On and off with Arduino
2. Playing with LED light bar
// On and off with Audrino
Demo Video :
Programme :
const int LED_PIN = 7 ;
const int LED2_PIN = 5 ;
const int BUTTON_PIN = 3 ;
const int BUTTON2_PIN = 8 ;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
}
// the loop function runs over and over again forever
void loop() {
if( digitalRead( BUTTON_PIN ) == LOW) { // pressed
digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
//digitalWrite(LED2_PIN, LOW);
delay(2000); // wait for a second
digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW
//digitalWrite(LED2_PIN, HIGH);
//delay(500); // wait for a second
} //else {
//digitalWrite(LED_PIN, LOW);
//digitalWrite(LED2_PIN, LOW);
if( digitalRead( BUTTON2_PIN ) == LOW) {
digitalWrite(LED2_PIN, HIGH); // turn LED on
delay(2000);
digitalWrite(LED2_PIN, LOW); // turn LED off
}
}
// Playing with LED light bar
Demo Video :
Programme :
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 4
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
pixels.clear();
pixels.show();
}
void loop() {
pixels.setPixelColor(0, pixels.Color(119, 252, 223)); // color
pixels.setPixelColor(1, pixels.Color(198, 110, 74)); // color
pixels.setPixelColor(2, pixels.Color(0, 39, 146)); // color
pixels.setPixelColor(3, pixels.Color(255, 232,48)); // color
pixels.show(); // This sends the updated pixel color to the hardware.
delay(1000);
pixels.clear();
pixels.show();
delay(1000);