Ok so i really really need someone to write a piece of code for me, that was supposed to be my homework for the entire summer and now i am out of time and it's not that easy learning code in like 3 days. If you are not the type that would help people in this case, please ignore this post and return to whatever you did before. If you are a nice guy willing to help a stranger out, help me with this staff please.
Sooooo i have been trying to set up a count up/down timer in arduino uno, and i feel like each time i change something in my code i make it even worse. The thing is that i need it to run count up/down without a clock (i need it tomorrow 9 A.M. i can't get a clock in that time), for more than hours. It has to include days months and years, or at least days in a 4 digit format (like 3650 days, and you know it's 10 years or so), and while doing that constantly checking on 3 voltmeters ( 30V max, using 2 resistors <10k and 100k> to create a voltage divider, on analog 1,2,3) and 2 ammeters. There is a second part of the code including some LEDs and a TFT LCD to display all that data on, but if it's possible just do it with Serial.print () and i will try to do the rest. This is the code i wrote/copied from the internet so far, it doesn't really work.
unsigned long Watch, _micro, time = micros();
unsigned int Clock = 0, R_clock;
boolean Reset = false, Stop = false, Paused = false, _type;
volatile boolean timeFlag = false;
#define DOWN 0
#define UP 1
void setup()
{
Serial.begin(9600);
SetTimer(0,23,59,59); // 10 seconds
StartTimer();
}
void loop()
{
CountUpDownTimer(DOWN); // run the timer
// this prevents the time from being constantly shown.
if (TimeHasChanged() )
Serial.print(ShowDays());
Serial.print(" days");
Serial.print(" ");
Serial.print(ShowHours());
Serial.print(":");
Serial.print(ShowMinutes());
Serial.print(":");
Serial.print(ShowSeconds());
Serial.print(" ");
delay(4000);
// This DOES NOT format the time to 0:0x when seconds is less than 10.
// if you need to format the time to standard format, use the sprintf() function.
}
boolean CountUpDownTimer(boolean Type)
{
_type = Type;
static unsigned long duration = 1000000; // 1 second
timeFlag = false;
if (!Stop && !Paused) // if not Stopped or Paused, run timer
{
// check the time difference and see if 1 second has elapsed
if ((_micro = micros()) - time > duration )
{
_type == UP? Clock++ : Clock--;
timeFlag = true;
if (_type == DOWN && Clock == 0) // check to see if the clock is 0
Stop = true; // If so, stop the timer
// check to see if micros() has rolled over, if not,
// then increment "time" by duration
_micro < time ? time = _micro : time += duration;
}
}
return !Stop; // return the state of the timer
}
void ResetTimer()
{
if(_type)
Clock = 0;
else
SetTimer(R_clock);
Stop = false;
}
void StartTimer()
{
Watch = micros(); // get the initial microseconds at the start of the timer
Stop = false;
Paused = false;
if(_type == UP)
Clock = 0;
}
void StopTimer()
{
Stop = true;
}
void StopTimerAt(unsigned int days, unsigned int hours, unsigned int minutes, unsigned int seconds)
{
if (TimeCheck(days, hours, minutes, seconds) )
Stop = true;
}
void PauseTimer()
{
Paused = true;
}
void ResumeTimer() // You can resume the timer if you ever stop it.
{
Paused = false;
}
void SetTimer(unsigned int days, unsigned int hours, unsigned int minutes, unsigned int seconds)
{
// This handles invalid time overflow ie 1(H), 0(M), 120(S) -> 1, 2, 0
unsigned int _H = (seconds / 3600),_S = (seconds / 60), _M = (minutes / 60);
if(_S) minutes += _S;
if(_M) hours += _M;
if(_H) days += _H;
Clock = (days * hours*23 + hours * 3600) + (minutes * 60) + (seconds % 60);
R_clock = Clock;
Stop = false;
}
void SetTimer(unsigned int seconds)
{
// StartTimer(seconds / 3600, (seconds / 3600) / 60, seconds % 60);
Clock = seconds;
R_clock = Clock;
Stop = false;
}
int ShowDays ()
{
return Clock / 86400;
}
int ShowHours()
{
return Clock / 3600;
}
int ShowMinutes()
{
return (Clock / 60) % 60;
}
int ShowSeconds()
{
return Clock % 60;
}
unsigned long ShowMilliSeconds()
{
return (_micro - Watch)/ 1000.0;
}
unsigned long ShowMicroSeconds()
{
return _micro - Watch;
}
boolean TimeHasChanged()
{
return timeFlag;
}
// output true if timer equals requested time
boolean TimeCheck(unsigned int days, unsigned int hours, unsigned int minutes, unsigned int seconds)
{
return (days == ShowDays() && hours == ShowHours() && minutes == ShowMinutes() && seconds == ShowSeconds());
}
*It's first year in college, i spent my summer drunk on the beach and someone reminded me that we are supposed to do this box with LED's and a display counter on it that tells what led get's what voltage and after 4 years he will give it back and it will serve as the first memory made in college. Help me people, i don't wan't to f**k it up day 1. Thank you in advance !