hi, i hope someone could help me.
I am suing:
arduini UNO R3.
6 LEDS
6 100R Resistors
1 potentiometer
i want to calculate the voltage and get a visual feedback of my leds.
somehow its not working as i want and i have 2 questions
1.) why do i get a serialmonitor output of 2 or 3 when i use the if and when i dont use them i get a outpur of 0
2.) the leds are all always turned on
i hope someone could help me, ty in forward
sincerely
sry i have some pic uploading problems - Unbenannt hosted at ImgBB — ImgBB
somehow its not working as i want
Please post "it" and explain what it should do and what it actually does. A wiring diagram would be helpful too.
i had some issues of uploading a picture of my code(i hope it works now) and right now im dloading fritzing.
i will send a layout if the code is not enaught
gfvalvo
January 31, 2018, 10:40pm
5
The three most useless things in aviation:
Runway behind you
Altitude above you
Fuel you left behind
The three most useless things on the Programming Forum:
Pictures of code
Fritzing circuit diagrams
Problem Statement: "it doesn’t work"
well ill try to explain...
i got 6 LEDs all assigned to PORTB (PIN 8 - 13)
i got a potentiometer assigned to AnalogIN (A0)
what it should do:
when the potentiometer is on lowest position no LEDs should be turned on
when the potentiometer is on med position 3 leds should be turned on
when the potentiometer is on max all leds should be turned on
what it does:
all LEDS are turned on even when the position is on med lor lowest
serial monitor shows always 3 even when the poti is on the lowest position (it should be 0)
my code:
void setup() {
Serial.begin(9600);
DDRB = B11111111;
PORTB = B00000000;
}
int LED[] = {B00000000, B00000001, B00000011, B00000111, B00001111, B00011111, B00111111};
void loop() {
int calculation = analogRead(A0);
if (calculation == 0) PORTB = LED[0];
if (calculation > 10) PORTB = LED[1];
if (calculation > 170,5)PORTB = LED[2];
if (calculation > 341) PORTB = LED[3];
if (calculation > 511,5)PORTB = LED[4];
if (calculation > 682) PORTB = LED[5];
if (calculation > 852,5)PORTB = LED[6];
Serial.println(calculation);
delay(1);
}
how funny i just recognised that a int value cant be 170,5 ...
the analogread cant be double
so i rounded the if values and it works now...
a bit pity, visual studio would recognise that for sure
PieterP
January 31, 2018, 11:07pm
8
A period is used as decimal separator, not a comma. If you had enabled your compiler warnings, it would have told you:
C:\Users\user\AppData\Local\Temp\arduino_modified_sketch_462634\sketch_feb01a.ino: In function 'void loop()':
C:\Users\user\AppData\Local\Temp\arduino_modified_sketch_462634\sketch_feb01a.ino:16:19: warning: left operand of comma operator has no effect [-Wunused-value]
if (calculation > 170,5)PORTB = LED[2];
^
Pieter
system
February 1, 2018, 10:29am
9
int LED[] = {B00000000, B00000001, B00000011, B00000111, B00001111, B00011111, B00111111};
That is a dumb name for the array. B00000001 is NOT an LED.
Meaningful names ARE important.