Hi,
I am trying to create a circuit with a potentiometer which changes the delay of the sequenced 6 leds, and then that delay time put into a formula and appears on the LCD.
im almost there but abit confused as i believe i need a code enhancement and am relatively new to using ardiunos
so every 6 leds blink i want 1 to be on the potentiometer per minute. so if the delay is 200ms between them flashing then every 1200ms:1
so 60,000/1200= 50 (the value i want to show on the display when the potentiometer is at 200ms between each led)
i need to string this value (which will be a variable and changed by pot) i believe instead.
So i need a led delay time to lcd.
The LCD display needs to display the what will be RPM which will be after every led has gone off in sequence, and the first led light up again.
For now i have managed to get the Ms of one led so the potentiometer has a display of 1023ms and works when i change the potentiometer resitance.
My problem is controlling the rate at which the delay between each led lighting up to the potentiometer.
I need to code the potentiate to the delay of all of them.
Please if you could assist as im a beginner in all of this.
I tried to connect the negative ports of leds all to the potentiometer by listing but im really stuck, im pretty sure im almost there, but need a nudge in the correct direction.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int L1 = 7; //This assigns names to pins
int L2 = 8;
int L3 = 9;
int L4 = 10;
int L5 = 13;
int L6 = 1;
int pwmPin = 7; // assigns pin 12 to variable pwm
int pwmPin2 = 8;
int pwmPin3 = 9;
int pwmPin4 = 10;
int pwmPin5 = 13;
int pwmPin6 = 1;
int pot = A0; // assigns analog input A0 to variable pot
int t1 = 0; // declares variable t1
int t2 = 0; // declares variable t2
char sole[5]; //initializing a character of size 5 for showing the ADC result
int isOn = 1;
int potRead = 0;
long now = 1;
void setup() {
lcd.begin(16, 2); //Registering the amount character/rows the lcd is specified at.
lcd.setCursor(0, 0);
delay(1000);
lcd.setCursor(0, 1);
lcd.print("delay: ");
pinMode(L1, OUTPUT); //Set the pins to coils as outputs ( LED)
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT); //Set the pins to coils as outputs
pinMode(L5, OUTPUT);
pinMode(L6, OUTPUT);
{
pinMode(pwmPin, OUTPUT);
pinMode(pwmPin2, OUTPUT);
pinMode(pwmPin3, OUTPUT);
pinMode(pwmPin4, OUTPUT);
pinMode(pwmPin5, OUTPUT);
pinMode(pwmPin6, OUTPUT);
pinMode(pot, INPUT);
}
if (millis() > now + potRead) {
digitalWrite(pwmPin, isOn);
isOn = 1 - isOn;
now = millis();
}
}
//ADD FOR RELAYS
//100ms
void loop() {
{
// set the cursor to column 0, line 1
lcd.print(" "); //print name
lcd.setCursor(0, 1); // set the cursor to column 0, line
lcd.print("delay:"); //print name
String delay = String(analogRead(A0)); //intailizing a string and storing ADC value in it
delay.toCharArray(sole, 5); // convert the reading to a char array
lcd.print(sole); //
lcd.print(" ");
lcd.setCursor(0, 0); // set the cursor to column 0, line1
}
digitalWrite(L1, HIGH);
delay(300);
digitalWrite(L1, LOW);
digitalWrite(L2, HIGH);
delay(300);
digitalWrite(L2, LOW);
digitalWrite(L3, HIGH);
delay(300);
digitalWrite(L3, LOW);
digitalWrite(L4, HIGH);
delay(300);
digitalWrite(L4, LOW);
digitalWrite(L5, HIGH);
delay(300);
digitalWrite(L5, LOW);
digitalWrite(L6, HIGH);
delay(300);
digitalWrite(L6, LOW);
{
t2 = analogRead(pot);
t1 = 1024 - t2; // -