-In your program, the temperatures in Fahrenheit should be given one at a time b
ID: 2294103 • Letter: #
Question
-In your program, the temperatures in Fahrenheit should be given one at a time by typing their value using the keyboard, and then display the given Fahrenheit and its corresponding Celsius value on the terminal as follows: 86 degree Fahrenheit- 30 degree Celsius - Next, the corresponding value for the Celsius Temperature in Binary should be displayed in the 8-LED connected to pins 2-9 of the Arduino, so that the LED will display the above Celsius temperature as 0001 1110. Using the Tinkercad software implement a circuit like the one shown in the following diagramExplanation / Answer
const byte Number_LED_PINs = 8; // Number of LED pins
int LED_state; //On or OFF
byte LED_PINS[] = {2, 3, 4, 5, 6, 7, 8, 9};
String readString;
int Fahrenheit = 0;
int Celsius = 0;
void setup()
{
Serial.begin(9600);
// Set all LED as output
for(int i = 0; i < Number_LED_PINs; i++)
{
pinMode(LED_PINS[i], OUTPUT);
}
}
void loop()
{
while (Serial.available())
{
char character = Serial.read();
readString += character;
delay(2);
}
int Fahrenheit = readString.toInt();
Celsius = (Fahrenheit-32)*(5/9);
Serial.print("Fahrenheit in Celsius :");
Serial.println(Celsius);
/* convert Celsius to binary and store it as a string */
String Celsius_string = String(Celsius, BIN);
int length_Celsius_string = Celsius_string.length();
if(Celsius <= 255)
{
for(int i = 0; i < length_Celsius_string; i++)
{
if(Celsius_string[i] == '0') LED_state = LOW;
if(Celsius_string[i] == '1') LED_state = HIGH;
digitalWrite(LED_PINS[i], LED_state);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.