hey guys,
I am new here this is my first post, and I am technically new to arduino. I got one a couple months back and have been tinkering around with different adafruit stuff. transistors, lcd's, oled's, relays, that sort of thing. however I have hit my first wall. My sketch is relatively small, 1630 bytes. and I believe there is supposed to be 27k. I have tried on multiple boards, all authentic, 2 different nano's and 2 different uno's. all with the same result which makes me think its my code, duh. but why, and how is my issue because if I pull the code and run everything individually everything runs fine. delay() is correct enough. but when I put it all together, delay goes by way way way to quick. so 420000 goes by in 4 seconds. if I add 4 zeros, it adds another 4 seconds. this is a guesstimate as I didn't have a stop watch but definitely not 7 minutes, or even 1. I tried blink without delay and that didn't work. I know that if I find the issue in this code I will find it in the blink without delay code as well as the problem is identical. I just cannot get delay or blink without delay to work as millis() is going by way to quick but only with a bigger code, something with 10 lines, everything is fine. I also reinstalled the arduino IDE thinking that a library was corrupt or something. I say millis() is to fast because blink without delay has the same issue.
Issue: entire code runs delay way way to quick. but bits of the code copied and pasted are treated correctly.
int soilPin = A1, soilPin2 = A2;
int soilPower = 10, soilPower2 = 11;
int pumpPin = 2, pumpPin2 = 3;
int ledGR = 12, ledRED = 13;
int val = 0, val2 = 0;
int pumpStatus = LOW;
int pumpStatus2 = LOW;
int pumpTime = 0;
int pumpTime2 = 0;
void setup() {
pinMode (pumpPin, OUTPUT);
pinMode (pumpPin2, OUTPUT);
pinMode (soilPin, INPUT);
pinMode (soilPin2, INPUT);
pinMode (soilPower, OUTPUT);
pinMode (soilPower2, OUTPUT);
pinMode (ledRED, OUTPUT);
pinMode (ledGR, OUTPUT);
delay(1000);
}
void loop() {
//check moisture
checkSoil(soilPower, soilPin, ledGR, val);
delay(50);
percent(val);
checkSoil(soilPower2, soilPin2, ledRED, val2);
delay(50);
percent(val2);
//run pump if moisture is under a certain threshold
if (val <= 60) {
pumpCycle(pumpPin, pumpStatus, pumpTime, ledGR);
}
if (val2 <= 60) {
pumpCycle(pumpPin2, pumpStatus2, pumpTime2, ledRED);
}
}
unsigned long checkSoil(int sPower, int APin, int led, int moist) {
//check moisture
digitalWrite (sPower, HIGH);
digitalWrite (led, HIGH);
delay(100);
moist = analogRead(APin);
delay(100);
digitalWrite (sPower, LOW);
digitalWrite (led, LOW);
return moist;
}
unsigned long percent (int value) {
//change analog reading to percentage number
value = map(value, 260, 1025, 0, 100);
value = map(value, 0, 100, 100, 0);
return value;
}
void pumpCycle(int pumpP, int pStatus, int pumpT, int led) {
//run pumps in intervals to fight heat
for (int x = 0; x < 4; x++) {
if (pStatus = LOW) {
pStatus = HIGH;
pumpT = 420000;
}
else {
pStatus = LOW;
pumpT = 210000;
}
digitalWrite (pumpP, pStatus);
digitalWrite (led, pStatus);
delay(pumpT);
}
}
please forgive me if I forgot some information. I want this on a 328p and I am using the arduino IDE 1.8.5
Thank you for even reading!
edit = I am positive this is a space issue due to the irrational behavior. but I am unsure of a solution.