This is for a class in which we are not allowed to use the Arduino Library (Not my choice or preference). I know to use DDRB for the B pins. This is the code that I have so far:
//Global pointers
unsigned char *portDDRB = (unsigned char *) 0x24;
unsigned char *portDataB = (unsigned char *) 0x25;
unsigned char *portPinB = (unsigned char *) 0x23;
void setup () {
//For the led output I know that I would do this
*portDDRB |= 0x80;
}
void loop () {
//And here the code would be like this to light up the light:
if (condition to turn on light) {
*portDataB |= 0x80;
}
// To Turn off the LED:
if (condition to turn off the light) {
*portDataB &= 0x7F
}
}
I would like for the light to turn on when the input of PB4 is HIGH (from a button press). I just am not sure on what to put in the condition statements or the setup functions.
When I set the DDRB to 0x80, is that just making the PB7 an output and the rest as input?
I am using the Arduino Mega ATmega2560 btw.
From the comments I have this:
//Global pointers
unsigned char *portDDRB = (unsigned char *) 0x24;
unsigned char *portDataB = (unsigned char *) 0x25;
unsigned char *portPinB = (unsigned char *) 0x23;
void setup () {
//For the led output I know that I would do this
*portDDRB |= 0x80;
}
void loop () {
//And here the code would be like this to light up the light:
if (portPinB & 0x10) {
*portDataB |= 0x80;
}
// To Turn off the LED:
else {
*portDataB &= 0x7F
}
}
if( PINB & _BV(PINB4) )
orif( PINB & (1<<PINB4) )
. PS by using setup and loop you are still using the Arduino library. PS2 you need to change DATAB to turn the led on, not DDRB|=
to=
, or the bit will only be set, and never cleared.