Hi,
I have a potentiometer and want it's value from 0 to 1023 choose what loop to go to. The different loops are named after the colors. If value of the potentiometer is 0 to 70 goto red, if value is 71 to 140 go to greed etc. Any ideas? Can i hava different loops that only can be interupted by the potentiometrs value or what can i do? right now ony red works and if i call green in the potentiometer it gives me all the "colors".
int potPin = 2; // select the input pin for the potentiometer
int ledPin1 = 13; // select the pin for the LED
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int val = 0;
const int red = 0; // variable to store the value coming from the sensor
const int green = 70; // variable to store the value coming from the sensor
const int blue = 140; // variable to store the value coming from the sensor
const int cyan = 210; // variable to store the value coming from the sensor
const int yellow = 280; // variable to store the value coming from the sensor
const int purple = 350; // variable to store the value coming from the sensor
const int white = 420; // variable to store the value coming from the sensor
const int color7change = 490; // variable to store the value coming from the sensor
const int color7flow = 560; // variable to store the value coming from the sensor
const int color7fade = 630; // variable to store the value coming from the sensor
const int color7drm = 700; // variable to store the value coming from the sensor
const int mix7colorskip = 770; // variable to store the value coming from the sensor
const int singlecolorflow = 840; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin1, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPin2, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPin3, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPin4, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // val får värdet från potentiometern mellan 0 och 1023
if (val > red) {
//RED
digitalWrite(ledPin1, LOW); // turn the ledPin on
// delay(val); // stop the program for some time
digitalWrite(ledPin2, HIGH); // turn the ledPin off
// delay(val); // stop the program for some time
digitalWrite(ledPin3, HIGH); // turn the ledPin on
// delay(val); // stop the program for some time
digitalWrite(ledPin4, HIGH); // turn the ledPin off
// delay(val); // stop the program for some time
//val = analogRead(potPin); // läser in nytt aktuellt värde från potentiometer och sparar i val
}
if (val > green) {
//GRÖN
digitalWrite(ledPin1, HIGH); // turn the ledPin on
digitalWrite(ledPin2, LOW); // turn the ledPin off
digitalWrite(ledPin3, HIGH); // turn the ledPin on
digitalWrite(ledPin4, HIGH); // turn the ledPin off
}
// val = analogRead(potPin); // läser in nytt aktuellt värde från potentiometer och sparar i val
if (val > blue) {
//BLUE
digitalWrite(ledPin1, LOW); // turn the ledPin on
digitalWrite(ledPin2, LOW); // turn the ledPin off
digitalWrite(ledPin3, HIGH); // turn the ledPin on
digitalWrite(ledPin4, HIGH); // turn the ledPin off
}
if (val > cyan) {
//CYAN
digitalWrite(ledPin1, HIGH); // turn the ledPin on
digitalWrite(ledPin2, HIGH); // turn the ledPin off
digitalWrite(ledPin3, LOW); // turn the ledPin on
digitalWrite(ledPin4, HIGH); // turn the ledPin off
}
if (val > yellow) {
//YELLOW
digitalWrite(ledPin1, LOW); // turn the ledPin on
digitalWrite(ledPin2, HIGH); // turn the ledPin off
digitalWrite(ledPin3, LOW); // turn the ledPin on
digitalWrite(ledPin4, HIGH); // turn the ledPin off
}
if (val > purple) {
//PURPLE
digitalWrite(ledPin1, HIGH); // turn the ledPin on
digitalWrite(ledPin2, LOW); // turn the ledPin off
digitalWrite(ledPin3, LOW); // turn the ledPin on
digitalWrite(ledPin4, HIGH); // turn the ledPin off
}
}