/* Program to read the analog value of the pin connected to the temperature sensor. * The potentiometer on the Wytec EduBase/EduPad board is connected pin 28. * The ADC has 12 bits for TivaC and 14 bits for MSP432 but default to 10 bits * in Energia. The resolution is set to 12 bit by the statement * analogReadResolution(12); * so the value has the range of 0 - 4095. * Assume the temperature sensor is an LM45, The value is scaled to degree F * then sent to the Serial monitor. * The bits 7-4 of the conversion result is also written to the LEDs. * Make sure the LCD interface selection jumper is set at "serial". * * Energia 1.6.10E18 */ const int LED[] = {3, 4, 19, 38}; void setup() { Serial.begin(9600); Serial.println("Temperature sensor:"); // initialize LED for display for (int i = 0; i < 4; i++) pinMode(LED[i], OUTPUT); digitalGroupWrite(LED, 4, 0); analogReadResolution(12); } /* Tiva TM4C123 */ //const int temp = PE_5; const int temp = 6; void loop() { int tempValue; float degreeC; float degreeF; // read the voltage fromm ADC tempValue = analogRead(temp); // write it to the Serial monitor Serial.print(" Temperature = "); // Serial.print(tempValue); // Serial.print(", "); degreeC = (float)tempValue / 4095 * 3.3 / 0.01; Serial.print(degreeC, 2); Serial.print(" C, "); degreeF = degreeC * 9.0 / 5.0 + 32; Serial.print(degreeF, 2); Serial.println(" F"); digitalGroupWrite(LED, 4, tempValue >> 4); // and write it to the LEDs delay(100); } // write to a group of output pins void digitalGroupWrite(const int* group, int length, int data) { for (int i = 0; i < length; i++) digitalWrite(group[i], data & (1 << i) ? HIGH : LOW); }