Skip to main content
Code formatting.
Source Link
Edgar Bonet
  • 45.2k
  • 4
  • 42
  • 81

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;

}

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.

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.

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.

added 2 characters in body
Source Link

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.

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.

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.

Source Link

Arduino Uno simple LED example with pointers

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.