/* Program to read the analog value of the pin connected to the pontentiometer. * 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. The value is sent to the Serial monitor. * The upper 4 bits of the conversion result is also written to the LEDs. * * Energia 1.6.10E18 */ const int LED[] = {3, 4, 19, 38}; void setup() { Serial.begin(9600); Serial.println("Potentiometer:"); // initialize LED for display for (int i = 0; i < 4; i++) pinMode(LED[i], OUTPUT); digitalGroupWrite(LED, 4, 0); analogReadResolution(12); } // Pin 28 is connected to a potentiometer const int pot = 28; void loop() { int potValue; // read the voltage fromm ADC potValue = analogRead(pot); // write it to the Serial monitor Serial.print(" potentiometer value = "); Serial.println(potValue, DEC); digitalGroupWrite(LED, 4, potValue >> 8); // 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); }