Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
int ledPin = 9;
int potPin = A2; // select the input pin for the potentiometer
int val = 0; // variable to store the value coming from the sensor
int seed = 92;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
val = analogRead(potPin)/4; // read the value from the sensor
Serial.println(val);
Serial.println();
if(val < 10){
digitalWrite(ledPin, LOW);
}
else if(val >= 10 && val < 34){
digitalWrite(ledPin, HIGH);
delayMicroseconds(1*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(9*seed);
}
else if(val >= 34 && val < 58){
digitalWrite(ledPin, HIGH);
delayMicroseconds(2*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(8*seed);
}
else if(val >= 58 && val < 82){
digitalWrite(ledPin, HIGH);
delayMicroseconds(3*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(7*seed);
}
else if(val >= 82 && val < 106){
digitalWrite(ledPin, HIGH);
delayMicroseconds(4*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(6*seed);
}
else if(val >= 106 && val < 130){
digitalWrite(ledPin, HIGH);
delayMicroseconds(5*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(5*seed);
}
else if(val >= 130 && val < 154){
digitalWrite(ledPin, HIGH);
delayMicroseconds(6*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(4*seed);
}
else if(val >= 154 && val < 178){
digitalWrite(ledPin, HIGH);
delayMicroseconds(7*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(3*seed);
}
else if(val >= 178 && val < 202){
digitalWrite(ledPin, HIGH);
delayMicroseconds(8*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(2*seed);
}
else if(val >= 202 && val < 226){
digitalWrite(ledPin, HIGH);
delayMicroseconds(9*seed);
digitalWrite(ledPin, LOW);
delayMicroseconds(1*seed);
}
else{
digitalWrite(ledPin, HIGH);
}
}
/*void loop()
{
//digitalWrite(ledPin, HIGH);
//delayMicroseconds(0);
digitalWrite(ledPin, LOW);
//delayMicroseconds(10);
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.