I am looking for an Arduino sketch that when a button is pressed the temperature
ID: 3656955 • Letter: I
Question
I am looking for an Arduino sketch that when a button is pressed the temperature display ( two 7 segment displays) changes from Fahrenheit to celcius and back. I also need to implement the debounce function. This is the code I am currently using to display the temp in Fahrenheit on the segment displays as well as my code so far. #include static int outputOnes[] = {7,8,9,10}; static int outputTens[] = {3,4,5,6}; // 8421 code lookup table. static int segs_encoding[][4] = {{0,0,0,0}, {0,0,0,1}, {0,0,1,0}, {0,0,1,1}, {0,1,0,0}, {0,1,0,1}, {0,1,1,0}, {0,1,1,1}, {1,0,0,0}, {1,0,0,1}}; const int buttonPin = 13; int lastbuttonState = LOW; int buttonState = 0; int temp; int tempTens; int tempOnes; int reading; float temperature = 0.0; dht11 DHT11; long lastDebounceTime = 0; long debounceDelay = 200; void setup() { DHT11.attach(2); Serial.begin(9600); Serial.println("DHT11 TEST PROGRAM "); Serial.print("LIBRARY VERSION: "); Serial.println(DHT11LIB_VERSION); for (int i = 0; i < 4; ++i) { pinMode(outputOnes[i], OUTPUT); pinMode(outputTens[i], OUTPUT); pinMode(buttonPin, INPUT); } delay(1000); } void loop() { int reading = digitalRead(buttonPin); buttonState = digitalRead(buttonPin); Serial.println(" "); int chk = DHT11.read(); Serial.print("Read sensor: "); switch (chk) { case 0: Serial.println("OK"); break; case -1: Serial.println("Checksum error"); break; case -2: Serial.println("Time out error"); break; default: Serial.println("Unknown error"); break; } Serial.print("Temperature (°C): "); Serial.println((float)(DHT11.celcius(), DEC)); temp = (float)DHT11.celcius(); Serial.println(temp,DEC); show_decimal(temp); delay(1000); } void show_decimal(int num) { show(0, num); } void show(int base, int num) { tempTens = num/10; tempOnes = num; for (int i = 0; i < 4; ++i) { if(segs_encoding[tempOnes][i] == 1) { digitalWrite(outputOnes[base + 3 - i] , HIGH); } else { digitalWrite(outputOnes[base + 3 - i] , LOW); } if(segs_encoding[tempTens][i] == 1) { digitalWrite(outputTens[base + 3 - i] , HIGH); } else { digitalWrite(outputTens[base + 3 - i] , LOW); } } }Explanation / Answer
can you please post the code in a readable way i will help you use eclipse or komodo edit it and paste here it will work
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.