I am using an Arduino UNO WIFI Rev2 (Atmel Mega 4809) for my project to alter the output state of a pin via port manipulation. I have a multimeter connected to Pin 8, monitoring the state of the pin. After executing this code, as given below, I expected the voltage to toggle between 5 and 0 v every 1 s. Unfortunately, it was not happening! Something is wrong with my code, since it is working properly if I use the digital write command. Just a note: this code complied properly. Any help to fix it will be useful.
-Ac
void setup() {
pinMode(8, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
VPORTB.OUT = VPORTB.IN & B1111110;
delay(1000);
VPORTB.OUT = VPORTB.IN | B00000001;
delay(1000);
}
Please be accurate; there is a difference between an Arduino Uno WiFi (which is 328P based) and an Arduino Uno WiFi Rev2 (which is 4809 based). Your code indicates the latter.
Thanks @stitech!
Updated code is attached for the rest of community who may face similar trouble.
@stitech
I found port maps for Atmega168 and Atmega8
I could not find maps for Atmega4809. Suggestions?
void setup() {
pinMode(8, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
VPORTE.OUT &= B11110111;
delay(1000);
VPORTE.OUT |= B00001000;
delay(1000); // wait for a second
}