Arduino RGB Blinker Poti

From S23Wiki
Jump to: navigation, search

Ardino RGB Blinker Poti

verwendet 2x poti unbestimmter bauart^^

int sensorPin1 = 0;    // select the input pin for the potentiometer
int sensorValue1 = 0;  // variable to store the value coming from the sensor
int sensorMin1 = 1000;  // minimum sensor value
int sensorMax1 = 0;     // maximum sensor value
int sensorPin2 = 1;    // select the input pin for the potentiometer
int sensorValue2= 0;  // variable to store the value coming from the sensor
int sensorMin2 = 1000;  // minimum sensor value
int sensorMax2 = 0;     // maximum sensor value
int  g1 = 13;
int  g2 = 11;
int  r1 = 12;
int  r2 = 10;
int  LED1 = 9;
int  LED2 = 8;
int  LED3 = 7;
int  LED4 = 6;
int  LED5 = 5;
int  LED6 = 4; 
int  LED7 = 3;
int  LED8 = 2;
int rgb1;
int rgb2;
void setup()
{
  pinMode(g1, OUTPUT);
  pinMode(g2, OUTPUT);
  pinMode(r1, OUTPUT);
  pinMode(r2, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);
  pinMode(LED8, OUTPUT);

  digitalWrite(g1, HIGH);

  // calibrate during the first five seconds 
  while (millis() < 5000) {
    sensorValue1 = analogRead(sensorPin1);

    // record the maximum sensor value
    if (sensorValue1 > sensorMax1) {
      sensorMax1 = sensorValue1;
    }

    // record the minimum sensor value
    if (sensorValue1 < sensorMin1) {
      sensorMin1 = sensorValue1;
    }
    sensorValue2 = analogRead(sensorPin2);
    digitalWrite(r1, HIGH);
    // record the maximum sensor value
    if (sensorValue2 > sensorMax2) {
      sensorMax2 = sensorValue2;
    }

    // record the minimum sensor value
    if (sensorValue2 < sensorMin2) {
      sensorMin2 = sensorValue2;
    }
  }


  // calibrate during the first five seconds 


  // signal the end of the calibration period
  digitalWrite(g1, LOW);
  digitalWrite(11, LOW);
}

void RGBgelb1() {      
  digitalWrite(LED1,HIGH);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,LOW);
  digitalWrite(g1,HIGH);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBgelb2() {      
  digitalWrite(LED5,HIGH);
  digitalWrite(LED6,LOW);
  digitalWrite(LED7,HIGH);
  digitalWrite(LED8,LOW);
  digitalWrite(g1,HIGH);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBlila1() {      
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,HIGH);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,LOW);
  digitalWrite(g1,LOW);
  digitalWrite(g2,HIGH);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBlila2() {      
  digitalWrite(LED5,LOW);
  digitalWrite(LED6,HIGH);
  digitalWrite(LED7,HIGH);
  digitalWrite(LED8,LOW);
  digitalWrite(g1,LOW);
  digitalWrite(g2,HIGH);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBblau1() {      
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,HIGH);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,HIGH);
  digitalWrite(g1,LOW);
  digitalWrite(g2,HIGH);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
}
void RGBblau2() {      
  digitalWrite(LED5,LOW);
  digitalWrite(LED6,HIGH);
  digitalWrite(LED7,HIGH);
  digitalWrite(LED8,HIGH);
  digitalWrite(g1,LOW);
  digitalWrite(g2,HIGH);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
}
void RGBrot1() {      
  digitalWrite(LED1,HIGH);
  digitalWrite(LED2,HIGH);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,LOW);
  digitalWrite(g1,HIGH);
  digitalWrite(g2,HIGH);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBrot2() {      
  digitalWrite(LED5,HIGH);
  digitalWrite(LED6,HIGH);
  digitalWrite(LED7,HIGH);
  digitalWrite(LED8,LOW);
  digitalWrite(g1,HIGH);
  digitalWrite(g2,HIGH);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBgruen1() {      
  digitalWrite(LED1,HIGH);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,HIGH);
  digitalWrite(g1,HIGH);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
}
void RGBgruen2() {      
  digitalWrite(LED5,HIGH);
  digitalWrite(LED6,LOW);
  digitalWrite(LED7,HIGH);
  digitalWrite(LED8,HIGH);
  digitalWrite(g1,HIGH);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
}
void RGBtuerkis1() {      
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,HIGH);
  digitalWrite(g1,LOW);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
}
void RGBtuerkis2() {      
  digitalWrite(LED5,LOW);
  digitalWrite(LED6,LOW);
  digitalWrite(LED7,HIGH);
  digitalWrite(LED8,HIGH);
  digitalWrite(g1,LOW);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
}
void RGBweiss1() {      
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,LOW);
  digitalWrite(g1,LOW);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBweiss2() {      
  digitalWrite(LED5,LOW);
  digitalWrite(LED6,LOW);
  digitalWrite(LED7,HIGH);
  digitalWrite(LED8,LOW);
  digitalWrite(g1,LOW);
  digitalWrite(g2,LOW);
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
}
void RGBaus1() {      
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,LOW);
  digitalWrite(LED4,LOW);
  digitalWrite(g1,LOW);
  digitalWrite(g2,LOW);
  digitalWrite(r1,LOW);
  digitalWrite(r2,LOW);
}
void RGBaus2() {      
  digitalWrite(LED5,LOW);
  digitalWrite(LED6,LOW);
  digitalWrite(LED7,LOW);
  digitalWrite(LED8,LOW);
  digitalWrite(g1,LOW);
  digitalWrite(g2,LOW);
  digitalWrite(r1,LOW);
  digitalWrite(r2,LOW);
}
void loop(){

  sensorValue1 = analogRead(sensorPin1);

  // apply the calibration to the sensor reading
  sensorValue1 = map(sensorValue1, sensorMin1, sensorMax1, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue1 = constrain(sensorValue1, 0, 255);
  sensorValue2 = analogRead(sensorPin2);

  // apply the calibration to the sensor reading
  sensorValue2 = map(sensorValue2, sensorMin2, sensorMax2, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue2 = constrain(sensorValue2, 0, 255);

  delay(sensorValue1); 
  rgb1 = (random (1, 7)); 
  switch (rgb1)         
  {
  case 1:
    RGBgelb1();
    break;
  case 2:
    RGBlila1();
    break;
  case 3:
    RGBblau1();
    break;
  case 4:
    RGBrot1();
    break;
  case 5:
    RGBgruen1();
    break;
  case 6:
    RGBtuerkis1();
    break;
  case 7:
    RGBweiss1();
    break;
  default: 
    RGBaus1();
    break;

  }

  delay(sensorValue1); 
  rgb1 = (random (1, 7));
  switch (rgb1)         
  {
  case 1:
    RGBgelb1();
    break;
  case 2:
    RGBlila1();
    break;
  case 3:
    RGBblau1();
    break;
  case 4:
    RGBrot1();
    break;
  case 5:
    RGBgruen1();
    break;
  case 6:
    RGBtuerkis1();
    break;
  case 7:
    RGBweiss1();
    break;
  default: 
    RGBaus1();
    break;

  }

  delay(sensorValue2); 
  rgb2 = (random (1, 7));
  switch (rgb2)         
  {
  case 1:
    RGBgelb2();
    break;
  case 2:
    RGBlila2();
    break;
  case 3:
    RGBblau2();
    break;
  case 4:
    RGBrot2();
    break;
  case 5:
    RGBgruen2();
    break;
  case 6:
    RGBtuerkis2();
    break;
  case 7:
    RGBweiss2();
    break;
  default: 
    RGBaus2();
    break;

  }

  delay(sensorValue2); 
  rgb2 = (random (1, 7));
  switch (rgb2)         
  {
  case 1:
    RGBgelb2();
    break;
  case 2:
    RGBlila2();
    break;
  case 3:
    RGBblau2();
    break;
  case 4:
    RGBrot2();
    break;
  case 5:
    RGBgruen2();
    break;
  case 6:
    RGBtuerkis2();
    break;
  case 7:
    RGBweiss2();
    break;
  default: 
    RGBaus2();
    break;
  }
}