Hello, I apologize if this is breaking any of the forum's rules, please let me know if I am and I will change things. I am working on a simple project. The goal is to get 6 LEDs to light up in a bilateral way, so every .5 seconds the LEDs will switch (for example the first 3 will turn on then after .5 seconds the other 3 will turn on, and this loop will run forever). The other thing I want to do is while this loop is running I want to be able to change the brightness of the LEDs using a potentiometer. Here is the code so far:
#define LED_1_PIN 5
#define LED_2_PIN 6
#define LED_3_PIN 3
#define LED_4_PIN 10
#define LED_5_PIN 8
#define LED_6_PIN 11
const int potPin = A0;
int readValue = 0;
int writeValue;
int brightness = 0;
int motorState = 0;
int inputVal = 0;
void setup()
{
Serial.begin(9600);
pinMode(potPin, INPUT);
pinMode(LED_1_PIN, OUTPUT);
pinMode(LED_2_PIN, OUTPUT);
pinMode(LED_3_PIN, OUTPUT);
pinMode(LED_4_PIN, OUTPUT);
pinMode(LED_5_PIN, OUTPUT);
pinMode(LED_6_PIN, OUTPUT);
}
void Potentiometer()
{
readValue = analogRead(potPin);
brightness = (255./1023.) * readValue;
if (readValue > 0)
{
vibrate();
}
}
void vibrate()
{
if(motorState == 0) {
analogWrite(LED_1_PIN, brightness);
analogWrite(LED_2_PIN, brightness);
analogWrite(LED_3_PIN, brightness);
analogWrite(LED_4_PIN, 0);
analogWrite(LED_5_PIN, 0);
analogWrite(LED_6_PIN, 0);
motorState = motorState + 1;
}
else if(motorState == 1)
{
analogWrite(LED_1_PIN, 0);
analogWrite(LED_2_PIN, 0);
analogWrite(LED_3_PIN, 0);
analogWrite(LED_4_PIN, brightness);
analogWrite(LED_5_PIN, brightness);
analogWrite(LED_6_PIN, brightness);
motorState = 0;
}
//analogWrite(LED_1_PIN, brightness);
//analogWrite(LED_2_PIN, brightness);
//analogWrite(LED_3_PIN, brightness);
//analogWrite(LED_4_PIN, brightness);
//analogWrite(LED_5_PIN, brightness);
//analogWrite(LED_6_PIN, brightness);
}
void loop()
{
Potentiometer();
/*
digitalWrite(LED_1_PIN, 1023);
digitalWrite(LED_2_PIN, LOW);
digitalWrite(LED_3_PIN, 1023);
digitalWrite(LED_4_PIN, LOW);
digitalWrite(LED_5_PIN, 500);
delay(400);
digitalWrite(LED_1_PIN, LOW);
digitalWrite(LED_2_PIN, HIGH);
digitalWrite(LED_3_PIN, LOW);
digitalWrite(LED_4_PIN, 500);
digitalWrite(LED_5_PIN, 200);
delay(400);
digitalWrite(LED_1_PIN, 500);
digitalWrite(LED_2_PIN, 200);
digitalWrite(LED_3_PIN, 0);
digitalWrite(LED_4_PIN, 500);
digitalWrite(LED_5_PIN, 0);
delay(400);
*/
}
I am very new at programming so any and all help would be great. Thank you!