/* Sample program to read the analog value of the pin connected to the photosensor. * The photosensor on the Wytec EduBase board is connected pin 27. The value is sent to the * Serial monitor. and the upper 4 bits of the conversion result is also written to the LEDs. * Shield the photosensor from light and the analog value decreases. */ /* Tiva TM4C123 */ //const int LED[] = {PB_0, PB_1, PB_2, PB_3}; 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); } /* Tiva TM4C123 */ //const int photo = PE_1; 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 (length--; length >= 0; length--) { digitalWrite(group[length], data & (1 << length) ? HIGH : LOW); } }