I am new to Arduino and I have recently started off by trying to turn on an LED connected to pin 13 on my Arduino Uno using pointers.
I opted to do this with pointers because this would give me a better understanding on what really goes behind when I use predefined Arduino functions.
My simple code looks like this,
uint8_t *data = (uint8_t *) 0x05; //PortB data register ptr (Since pin 13 is PB6)
uint8_t *dir = (uint8_t *) 0x04; //PortB dir register ptr (Since pin 13 is PB6)
void setup() {
*dir = 0x40; //PB6 direction set to O/P
*data = 0x40; //PB6 data set to 1 to turn on the LED
}
void loop() {
*data = 0x40;
}
I tried the same program using pinMode(13, OUTPUT) and digitalWrite(13, LOW) functions and it works fine. But I do not understand what could be wrong with my pointers. If you find anything wrong, kindly let me know.