High vs Low

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.

0750 != 750
0500 != 500

Won't delayTime = analogRead(0); set A0 back to an input and cockup digitalWrite(A0, LOW); delay(0750); digitalWrite(A0, HIGH); delay(0500);

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.

Thanks.. Tom.. :slight_smile:

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.

I was looking at that ... is his typing an 'O' or '0'
The compiler would swallow a leading zero, but you're correct the letter 'O' would be an issue!

It was a zero. You mightn't notice the difference between 488 ms and 750 ms unless you are paying close attention.

it changes how long the light is ON

What light? Schematic?

Please use code tags.

lastchancename:
The compiler would swallow a leading zero, but you're correct the letter 'O' would be an issue!

No, it doesn't "swallow" a leading zero. It considers a number with a leading zero as in octal (base 8).

If you don't believe me, try compiling this simple program:

void setup () {}
void loop ()
 {
 delay (0950);
 }

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.

Hi,

4 LEDs are attached from the power on the breadboard back to the A0-A3 connections.

Do you have current limit resistors in series with each of the LEDs?

Tom... :slight_smile:

No, no resistors. They can run individually from a 9v directly.

Hi,

ajdeployed12:
No, no resistors. They can run individually from a 9v directly.

Okay they have built in resistors?
Tom.... :slight_smile:

Not to my knowledge

Also, what code would I use to keep something always on?

Hi,

  • 1.85-2.5V Forward Voltage, at 20mA current

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.

Tom… :slight_smile:

OK, I will throw in some resistors.