SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By riverapo
#148494
Hi,

I am trying to replicate the functions of the alarm clock for the ClockIt kit on Sparfun using the arduino coding instead of AVR which is the code that comes installed is the firmware on the kit. Can anyone help translate the coding from AVR to arduino coding for this kit? The code is in the documents section at the bottom of this link: https://www.sparkfun.com/products/10930

Thank you in advance.

-Rivera
By Visual Micro
#149680
I can tell you how to make it compile okay but not if it will then work or not, hopefully it's okay :)

1) Open the arduino ide and create a new sketch of the desired name
2) Paste the contents of the .c source file from your link into the new arduino source, so that the source code from the .c is all that is in the new arduino sketch
2) In the source code, find the "main()" method which is shown below :-
Code: Select all
int main (void)
{
	ioinit(); //Boot up defaults
	
	while(1)
	{
		check_buttons(); //See if we need to set the time or snooze
		check_alarm(); //See if the current time is equal to the alarm time
	}
	
    return(0);
}
Rename the main() method to loop(), change the code shown above to be like the example below, you must also add the setup() method (as shown below):-
Code: Select all
void setup()
{
}
void loop(void)
{
	ioinit(); //Boot up defaults
	
	while(1)
	{
		check_buttons(); //See if we need to set the time or snooze
		check_alarm(); //See if the current time is equal to the alarm time
	}
	
   // return(0);
}
OR: to develop this to use the arduino setup() method in a more normal way you should be able to do this:-
Code: Select all
void setup()
{
	ioinit(); //Boot up defaults
}
void loop(void)
{
		check_buttons(); //See if we need to set the time or snooze
		check_alarm(); //See if the current time is equal to the alarm time
}