Arduino programming fagcafe - Levende lamper
by Daniel Davidsen
access to presentation:
PowerPoint file
access to files:
Demo example
Here is the presentation but as a blog post, not to be followed but for easy to scroll and look.
Download and install Arduino
Download link: https://www.arduino.cc/en/software
Add “FastLED” library
Settings: Turn on “editor quick suggestions”
First code - Blink test
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Blink and print over USB
void setup() {
Serial.begin(9600); //setup USB port for communication
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("ON"); // Print on serial "ON"
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.println("OFF"); // print on Serial "OFF"
delay(1000); // wait for a second
}
Blink with LED string
#include <FastLED.h>
#define NUM_LEDS 1
#define DATA_PIN 3
CRGB leds[NUM_LEDS]; // Define the array of leds
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
}
void loop() {
leds[0] = CRGB::Red; // Set the LED 0 red
FastLED.show(); // Push the state to all LEDs
delay(1000); // Pause for 1 sec
leds[0] = CRGB::Black; // Set the LED 0 red
FastLED.show(); // Push the state to all LEDs
delay(1000); // Pause for 1 sec
}
favourite shortcut list
Copy = Ctrl + z
Paste = Ctrl + v
Undo = Ctrl + z
Upload = Ctrl + u
Auto format = Ctrl + t
Turn all LED’s Red
void loop() {
leds[0] = CRGB::Red;
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[4] = CRGB::Red;
(...)
leds[23] = CRGB::Red;
leds[24] = CRGB::Red;
FastLED.show();
}
Turn all LED’s blue with loop
void loop() {
counter = counter + 1; //increase number with + 1
Serial.println(counter);
leds[conuter] = CRGB::Blue;
FastLED.show();
delay(1000);
}
/*
This code will work but is very bad as number will increase to a very high number ( and sooner or later loop over to zero again)
*/
Turn all LED’s blue with 'for-loop'
void loop() {
for (int counter = 0; counter < NUM_LEDS; counter++) {
Serial.println(counter);
leds[conuter] = CRGB::Red;
FastLED.show();
delay(1000);
}
Now have some fun with the demoreel example there has been modified to only use function you have learned doing this workshop.
Demo example