Arduino RGB Blinker

From S23Wiki
Jump to: navigation, search

Schaltung folgt irgendwann :>

Arduino RGB Zufallsblinker neverending

int  LED1 = 10;
int  LED2 = 11;
int  LED3 = 12;
int  LED4 = 13;
int  LED5 = 6;
int  LED6 = 7;
int  LED7 = 8;
int  LED8 = 9;
int rgb;

void setup()
{
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);
  pinMode(LED8, OUTPUT);
}

void loop()
{
delay(random (50, 250));
rgb = (random (1, 7)); // random rgb 1-7
  switch (rgb)         // switch rgb 1--7 farbwert
  {
  case 1:
    // gelb
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    digitalWrite(LED5,HIGH);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  case 2:
    //lila
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,HIGH);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  case 3:
    // blau
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,HIGH);
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,HIGH);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,HIGH);
    break;
  case 4:
    // rot
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    digitalWrite(LED5,HIGH);
    digitalWrite(LED6,HIGH);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  case 5:
    // gruen
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,HIGH);
    digitalWrite(LED5,HIGH);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,HIGH);
    break;
  case 6:
    // tuerkis
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,HIGH);
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,HIGH);
    break;
  case 7:
    //weiss
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  default: 
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(LED4,LOW);
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,LOW);
    digitalWrite(LED8,LOW);
    break;
  }
}

<youtube>qyphaRlze4c</youtube>

Arduino RGB Blinker V2.0

so sieht das sogar langsam brauchbar aus

int  LED1 = 10; //led1
int  LED2 = 11; //led1 
int  LED3 = 12; //led1
int  LED4 = 13; //led1
int  LED5 = 6; //led2
int  LED6 = 7; //led2
int  LED7 = 8; //led2
int  LED8 = 9; //led2
int rgb1;
int rgb2;
void setup()
{
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);
  pinMode(LED8, OUTPUT);
}

void loop()
{
delay(random (100, 250));
rgb1 = (random (1, 7)); // random rgb1 1-7
  switch (rgb1)         // switch rgb1 1--7 farbwert
  {
  case 1:
    // gelb
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    break;
  case 2:
    //lila
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    break;
  case 3:
    // blau
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,HIGH);
    break;
  case 4:
    // rot
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    break;
  case 5:
    // gruen
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,HIGH);
    break;
  case 6:
    // tuerkis
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,HIGH);
    break;
  case 7:
    //weiss
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(LED4,LOW);
    break;
  default: 
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(LED4,LOW);
    break;
  }
  
  delay(random (100, 250));
  rgb2 = (random (1, 7)); // random rgb2 1-7
  switch (rgb2)         // switch rgb2 1--7 farbwert
  {
  case 1:
    // gelb
    digitalWrite(LED5,HIGH);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  case 2:
    //lila
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,HIGH);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  case 3:
    // blau
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,HIGH);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,HIGH);
    break;
  case 4:
    // rot
    digitalWrite(LED5,HIGH);
    digitalWrite(LED6,HIGH);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  case 5:
    // gruen
    digitalWrite(LED5,HIGH);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,HIGH);
    break;
  case 6:
    // tuerkis
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,HIGH);
    break;
  case 7:
    //weiss
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,HIGH);
    digitalWrite(LED8,LOW);
    break;
  default: 
    digitalWrite(LED5,LOW);
    digitalWrite(LED6,LOW);
    digitalWrite(LED7,LOW);
    digitalWrite(LED8,LOW);
    break;
  }
}

<youtube>NJvHYRL5lo0</youtube>