Hi, I'm having trouble with a program I made for my uno. My output 7 seems to work just like i want it to. But once I define any other pin as an output it goes high. Specifically, 3 and 5 in my code but i have tried 3,5,8,13 with the same results. If i add a line digitalWrite(x,LOW); it will stay high but digitalWrite(x,HIGH); will set it low. Does this make sense? What am I doing wrong?
const unsigned long light0trigger = 43200000; // define light0 time
unsigned long light0previoustime = 0; //update light0 time
int light0state = 0; //variable for light0 state
void setup() // put your setup code here, to run once:
{
Serial.begin(9600); // start serial
pinMode (3,OUTPUT); // 3 is pump0
pinMode (5,OUTPUT); // 5 is pump1
pinMode (7,OUTPUT); // 7 is light0
pinMode (A0,INPUT); // a0 is soil0
pinMode (A1,INPUT); // a1 is soil1
}
void loop() //main loop
{
unsigned long currenttime = millis(); // saves current milis value to variable and updates
int soil0 = analogRead(A0); // defines A0 as a variable and updates
int soil1 = analogRead(A1); // defines A1 as a variable and updates
if (currenttime - light0previoustime >= light0trigger) // if currenttime minus light0previoustime is greater than or equal to light0trigger
{
light0previoustime = currenttime; //updates light0previous time to currenttime
if (light0state % 2 == 0) // if light0state is even turn on light0 else turn it off
{
digitalWrite (7,HIGH);
light0state++; // add one to light0state
}
else
{
digitalWrite (7,LOW);
light0state++;
}
}
}