Step 2Re-using Arduino files for micro and the timer
You can find the files needed in the Arduino folder:
hardware/arduino/cores/arduino (yes two times arduino)
there you find the arduino files, which saves a lot of people learning the C of AVR :-), but at a cost of speed and size.
I needed the micro functions and the interrupt, which I found in wiring.c
I copied: (also copying the variables and defines I needed from wiring.h)
SIGNAL(TIMER0_OVF_vect)
unsigned long millis()
unsigned long micros()
but very important, to get the timer/interrupt started is the:
void init()
There is a lot of code you can skip if you know you use a atmega328.
Then we get this code in two nice files, a source and a header:
http://http//:www.contrechoc.com/instructables/infra-red.zip
(This is a total AVR project you can use for further fun.)
Also included here are, a UART.c and UART.h, for communication with the liquid crystal.
You see I have made the fill an int variable.
Also the analog read is activated for an LDR, and one pin is used to make the other shoulder light up when a signal at 38kHz is received.
initTimers(); is used to start the interrupts, the init() function from wiring.c
In the header file you find the connections with the groups of LED's (flexible LED strips)
//connections to PIN's from the led circle
unsigned char rows[8] = { 7, 6, 5, 4, 3 , 2, 1, 0 };
unsigned char cols[8] = { 15, 14, 13, 12, 11, 10, 9, 8 };
The interrupt function is different from the flexible LED strips I used before:
SIGNAL(TIMER0_OVF_vect)
In this function, besides the "Arduino code" I have added my own interruptFie();
This function takes care of the LED block MATRIX activities.
In the setIRPattern(uint8_t count) function you see the matrix for the LED's on the shoulder band.
The 3's indicate the missing LED's form the 64 (I didn't use the full 64 = 8 x 8 LED's in the vest.)
| « Previous Step | Download PDFView All Steps | Next Step » |









































AVR C is of course dedicated for the avr chip, this is a link to basic C scripts for the atmega328 (or other):
https://www.mainframe.cx/~ckuethe/avr-c-tutorial/
the scripts can be uploaded using a programmer.
The dedicated part consists of the many registers and their names.
If you understand this part, you can put this code also in the Arduino scripting window, it works! (Mind the setup and loop seperation.)
The files of the Arduino "hiding" this same C code are in the Arduino folder, hardware, arduino....
You could also write C in Eclipse, Google for links.