Question
Rewrite the following Arduino code using C code and registers. You may only use Arduino code for the serial and delay functions. #define LED_PIN 13
Rewrite the following Arduino code using C code and registers. You may only use Arduino code for the serial and delay functions.
#define LED_PIN 13
char inChar;
boolean isFreshInChar;
void setup() {
pinMode(LED_PIN , OUTPUT);
digitalWrite(LED_PIN , LOW);
// Set serial monitor console termination for 'No line ending'
Serial.begin(9600);
Serial.println("Lab 1: hello arduino v0.3 ");
delay(5000);
}
void loop() {
isFreshInChar = false;
if (Serial.available()) {
inChar = Serial.read();
Serial.print("Serial input detected: ");
Serial.println(inChar);
isFreshInChar = true;
}
if (inChar == 'n') digitalWrite(LED_PIN , HIGH); // oN
if (inChar == 'f') digitalWrite(LED_PIN , LOW); // oFf
if (inChar == 'b') { // blink with 25% duty cycle
digitalWrite(LED_PIN , HIGH);
delay(250);
digitalWrite(LED_PIN , LOW);
delay(750);
}
// Discover 't' persistence bug by observing high rate LED blink
if (inChar == 't') { // toggle
digitalWrite(LED_PIN , !digitalRead(LED_PIN ));
}
// Add state change detection to get proper toggle action.
if (inChar == 'T') { // toggle
if (isFreshInChar) digitalWrite(LED_PIN , !digitalRead(LED_PIN ));
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started