/* Program to read the analog value of the pin connected to the photo sensor. * The potentiometer on the Wytec EduBase/EduPad board is connected pin 27. * 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("Photosensor:"); // initialize LED for display for (int i = 0; i < 4; i++) pinMode(LED[i], OUTPUT); digitalGroupWrite(LED, 4, 0); analogReadResolution(12); } // Pin 27 is connected to a photo sensor const int photo = 27; void loop() { int photoValue; // read the voltage fromm ADC photoValue = analogRead(photo); // write it to the Serial monitor Serial.print(" Photosensor value = "); Serial.println(photoValue, DEC); digitalGroupWrite(LED, 4, photoValue >> 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); }