So I am under the impression that HIGH is ON and LOW is OFF. However, I am running the following code and it is opposite, I change the first delay number (LOW listed as 0750) and it changes how long the light is ON. Can anyone explain?
int delayTime = 0;
void setup()
{
//declare A0-A3 as outputs
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
}
void loop()
//the loop will repeat over and over again
{
delayTime = analogRead(0);
//We are now setting our delay TIme from 0 to the number being read on A0 which is the position of the rotory shaft on the pot. digital
digitalWrite(A0, LOW); delay(0750); digitalWrite(A0, HIGH); delay(0500);
digitalWrite(A1, LOW); delay(0750); digitalWrite(A1, HIGH); delay(0500);
digitalWrite(A2, LOW); delay(0750); digitalWrite(A2, HIGH); delay(0500);
digitalWrite(A3, LOW); delay(0750); digitalWrite(A3, HIGH); delay(0500);
}
Low is low - when you write an output, it drives it to 0v (with digitalRead, low is what you get below ~3v? The exact cutoff is in the datasheet).
High is high, when you write an output high, it drives it to Vcc (typically 5v).
Whether high or low turns the connected device on depends on how you wired it. If you connect the positive side of the load to 5v, and the negative side to the pin, driving the pin low will turn it on. If you connect it the other way around, driving the pin high will turn it on.
It's often customary to switch the low side - Arduino pins are symmetric, but many devices are better at driving a pin low than high (it's easier, in terms of manufacturing), and some, termed "open drain" or "open collector" can't drive a pin high at all (often this is desirable)
Whether HIGH or LOW means that a switch is pressed depends on how the switch is wired. It is never a good idea to assume that either value means pressed.
Hi,
Does you code do as it is supposed to?
You read a value from the pot, 0 to 1023.
And that is all you do with it.
Is it supposed to adjust the delays?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png
Until we see how you have wired you LEDs and pot, explaining how HIGH LOWs work is not very easy.
0750 is an octal constant equal to 0B000111101000 . Octal constants were important back when C was build to be the language of Unix, and Unix used three three-bit quantities for file permissions.
Analog outputs take a value from 0-255, not HIGH/LOW. HIGH has the value 1 (usually). So you are changing an analog out from 0/255 to 1/255. You won't notice much difference.
Wow, I'd forgotten about that...
(of course, I doubt I'll ever use octal again after that stint in the 80s!)
My last outing was flipping switches on. PDP-11 front panel!
Thx.
The system is working as intended, it just turns on when LOW runs and off when HIGH runs. I will try to upload a picture, I don't have the expertise to draw a proper schematic. That was the first code I "wrote" (copied and customized from another online source).
Basically a wire runs from the 5v on the Arduino Mega to the positive on a breadboard.
4 LEDs are attached from the power on the breadboard back to the A0-A3 connections.
If you are using these LEDs, they need series current limit resistors to limit the current to 20mA or less, this is to protect the LED and the arduino output pin, which is rated at 40mA.
Without the resistor you will be driving the LED with more than 40mA, surprised the controller hasn't had problems.