After getting blinky to work (like i had to really do anything :p ) i thought id check out the timers. It seems to me that there are approx 4 general purpose timers. SOOOOOOOOOOOOOO many options.
I wrote up something just to start,stop,and read a timer. Nothing fancy, I just wanted to see it work ! I'll attempt to keep appending this with new unlocked features (lol..yes it does sound like a video game)...there are so many things that can be done with timers...hopefully i can create my own timer library that would do basic to intermediate tasks...i'll post more as I progress
#include "stdlib.h"
HardwareUsb Serial;
int ledPin = 13; // LED connected to digital pin 13
char rxBuffer;
uint8 numTimer=0;
uint8 timerArray[4] = {1,2,3,4};
uint16 counterVal;
uint8 loopControl=0;
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
timer_general_init(timerArray[1],1); //timer 2, 1 prescale
timer_general_init(timerArray[2],1); //timer 3, 1 prescale
timer_general_init(timerArray[3],1); //timer 4, 1 prescale
Serial.print("Enter Timer No.:");
}
void loop()
{
Serial.print("Timer No.:");
loopControl=0;
while(!loopControl )
{
if(Serial.available() > 0 )
{
loopControl = 1;
rxBuffer = Serial.read();
if(rxBuffer == '1')
numTimer = 1;
else if(rxBuffer == '2')
numTimer = 2;
else if (rxBuffer == '3')
numTimer = 3;
else if (rxBuffer == '4')
numTimer = 4;
else
numTimer = 2; //lets this as the default timer
}
}
Serial.print("Timer ");
Serial.println(numTimer);
Serial.print("Command:");
while(loopControl)
{
if(Serial.available() > 0 )
{
rxBuffer = Serial.read();
if(rxBuffer == 'r') //read
{
counterVal=timer_read_count(numTimer); //read current timer val
Serial.print("Counter:");
Serial.println(counterVal);
}
else if(rxBuffer == 'd') //disable
{
timer_en_dis(numTimer,0);
}
else if (rxBuffer == 'e') //enable
{
timer_en_dis(numTimer,1);
}
else if (rxBuffer == 'b') //back out
{
loopControl =0;
}
else
{
Serial.println();
Serial.println("Invalid");
Serial.println("Command:");
}
}
//timers_set_reload(numTimer,inByte);
//countVal=timer_read_count(numTimer);
//Serial.println(counter);
}
}
lol..i'll make it look prettier later..but feel free to change it up to test the timers out so you know how it works. This was something quick for me and suited my curiosity but if you want to add more...please do and POST HERE !! sharing ftw !