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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!