In: Computer Science
Write a program that captures the transmission of a character from an Arduino board over serial communication (UART)
Answer : Given data
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(crankingPin, INPUT);
pinMode(liftoffPin, INPUT);
pinMode(upwardPin, INPUT);
pinMode(downwardPin, INPUT);
pinMode(turnleftPin, INPUT);
pinMode(turnrightPin, INPUT);
pinMode(forwardPin, INPUT);
pinMode(backwardPin, INPUT);
}
void loop()
{
if(digitalRead(offPin)==HIGH)
{
Serial.write('0');
delay(1000);
}
if(digitalRead(crankingPin)==HIGH)
{
Serial.write('1');
delay(1000);
}
if(digitalRead(liftoffPin)==HIGH)
{
Serial.write('2');
delay(1000);
}
if(digitalRead(upwardPin)==HIGH)
{
Serial.write('3');
delay(1000);
}
if(digitalRead(downwardPin)==HIGH)
{
Serial.write('4');
delay(1000);
}
if(digitalRead(turnleftPin)==HIGH)
{
Serial.write('5');
delay(1000);
}
if(digitalRead(turnrightPin)==HIGH)
{
Serial.write('6');
delay(1000);
}
if(digitalRead(forwardPin)==HIGH)
{
Serial.write('7');
delay(1000);
}
if(digitalRead(backwardPin)==HIGH)
{
Serial.write('8');
delay(1000);
}
}
_____________THE END__________________