It looks like you're new here. If you want to get involved, click one of these buttons!
/*
Description: Potentiometer with increasing LEDs (ok it's a short description)
Coded by: Sh3llc0d3
*/
int greenPinOne = 10; // initialises green led (#1) on pin 10
int greenPinTwo = 11; // initialises green led (#2) on pin 11
int redPinOne = 12; // initialises red led (#1) on pin 12
int redPinTwo = 13; // initialises red led (#2) on pin 13
void setup() {
pinMode(greenPinOne, OUTPUT); // This just sets the pins up and declares
pinMode(greenPinTwo, OUTPUT); // the above variables(pins/leds) as outputs.
pinMode(redPinOne, OUTPUT);
pinMode(redPinTwo, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0); // I have a potentiometer hooked up to A0 (analogue pin 0) ...this declares the variable and reads input from A0.
if (sensorValue == 0) // This next bit it pretty simple, just pretty much involves if statements... well it does... the if's
{ // read the value from the potentiometer and then respond giving the correct output via the led lights.
digitalWrite(redPinOne, LOW);
digitalWrite(redPinTwo, LOW);
digitalWrite(greenPinOne, LOW);
digitalWrite(greenPinTwo, LOW);
}
if (sensorValue > 0 && sensorValue <= 250)
{
digitalWrite(redPinOne, LOW);
digitalWrite(redPinTwo, LOW);
digitalWrite(greenPinOne, HIGH);
digitalWrite(greenPinTwo, LOW);
}
if (sensorValue > 250 && sensorValue <= 500)
{
digitalWrite(redPinOne, LOW);
digitalWrite(redPinTwo, LOW);
digitalWrite(greenPinOne, HIGH);
digitalWrite(greenPinTwo, HIGH);
}
if (sensorValue > 500 && sensorValue <= 750)
{
digitalWrite(redPinOne, HIGH);
digitalWrite(redPinTwo, LOW);
digitalWrite(greenPinOne, HIGH);
digitalWrite(greenPinTwo, HIGH);
}
if (sensorValue > 750 && sensorValue < 1000)
{
digitalWrite(redPinOne, HIGH);
digitalWrite(redPinTwo, HIGH);
digitalWrite(greenPinOne, HIGH);
digitalWrite(greenPinTwo, HIGH);
}
}