Code für Side Glow Optic Fibre Sample

Code für zwei RGB-LEDs und Side Glow Optic Fibre

Mit diesem Code werden zwei RGB-LEDs so angesteuert, dass sie zufällig in rot grün oder blau aufleuchten. In dem Stück Side Glow Optic Fibre mischen sich die Farben.

Um den Code zu benutzen, öffne ein neues Fenster in der Arduino IDE. Lösche alles heraus, was dort drin steht. Kopiere dann den kompletten Code unten und füge ihn in das Fenster der Arduino IDE ein. Lade den Code dann auf Dein Adafruit Flora Board.

Code für das Side Glow Optic Fibre Sample

//Connect the Flora Board with a DATA-Cable!!!!
//Board: choose Adafruit Flora
//Programmer: „Arduino as ISP“ works fine
//turn on the board with the onboard switch

//connect 2 RGB LEDs
//put a piece of side glow optic fibre in between

//for the first RGB led (each leg is connected to its own pin on the Flora)
int led6 = 6; //one leg of the first RGB led is connected to pin 6 on the Flora board
int led10 = 10; //one leg of the first RGB led is connected to pin 10 on the Flora board
int led9 = 9; //and so on…

//for the second led
int led2 = 2;
int led3 = 3;
int led12 = 12;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins as an output. These are the six pins that we connect our LEDs to.

pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led12, OUTPUT);
Serial.begin(9600); //This turns on the Serial monitor. This is only for checking the random values on screen!
// the loop routine runs over and over again forever:
void loop() {
int duration = random(0,1000); //We randomly generate values between 0 and 999 milliseconds.
//We will later turn on one of our leds for exactly this time.

//choose which leg of the RGB led receives power
int led = random (0,3); //each led can light up in 3 different colors (values 0-2)
int led2 = random (0,3);
int breaktime = random(0,50); //Randomly generate a value between 0 and 49

//print the randomly generated values onto the screen
Serial.print(„Duration: „);
Serial.print(„led: „);
Serial.print(„Breaktime: „);

//We program two switches one for each RGB led:
switch (led){
case 0: digitalWrite(led6, HIGH);break;
case 1: digitalWrite(led9, HIGH);break;
case 2: digitalWrite(led10, HIGH);break;

switch (led2){
case 0: digitalWrite(led12, HIGH);break;
case 1: digitalWrite(led2, HIGH);break;
case 2: digitalWrite(led3, HIGH);break;

digitalWrite(led6, LOW); //turn off all LEDs for the time that we randomly generated for „breaktime“
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led12, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);

Zurück zur Code-Übersicht: -> Code für E-Textile-Workshop Samples