Step 4C++ Source code
#include <stdio.h>
int main(void);
void do_something(void);
int main(void) {
do_something();
}
void do_something(void) {
/* comment */
}
The Arduino IDE does not require this step, as functions prototypes are generated automatically. Therefore function prototypes won't show up in the code shown here.
Image (1): setup() function
Image (2): spi_transfer() function using hardware SPI of the ATmega168 chip (runs faster)
Image (3): framebuffer code using a timer1 overflow interrupt.
Pieces of code that have a slightly cryptic look for beginners e.g. while(!(SPSR & (1<<SPIF))) {} use the MCU's registers directly. This example in words: "while the the SPIF-bit in register SPSR is not set do nothing".
I just want to emphasize that for standard projects it is really not necessary to deal with these things so closely related to hardware. Beginners should not be frightened by this.
| « Previous Step | Download PDFView All Steps | Next Step » |



















































I have one week to make an RGB LED matrix for school. How did you wire your matrix up before you transferred it all to PCB? Due to time and money constraints, I can't have a PCB manufactured. Do you have photos, schematics, or diagrams?
Before it was transfered to a PCB, I uses a breadboard to test the circuit. Suffice to say that it was no fun at all. So many wires...
If you go to my blog (the link is here somewhere), you will find schematics and photos (flickr) and some code as well. The best entry point is the projects page. Other posts may have outdated content. If you intend to use any of it, make sure to get the latest versions of both from the git repositories, otherwise it may have unpredictable effects.
Good news, I have success in having a working RGB matrix after following your codes and instruction.
May I know how do i modify the code if I want to run it on a stand alone ATMEGA168/328 but NOT from a Arduino?
Thank you again!
Just make sure the FUSE settings of the chips are correct. For an 168 these would be:
a) no bootloader, 16MHz quartz, 16kb usable:
lock: 0x3F
lfuse: 0xFF
hfuse: 0xDD
efuse: 0x01
b) with bootloader, 16MHz quartz, 14kb usable:
lfuse: 0xFF
hfuse: 0xDD
efuse: 0x00