Skip to content

Instantly share code, notes, and snippets.

@rafacouto
Last active August 29, 2015 14:16
Show Gist options
  • Save rafacouto/a9e58598e7bbfe3b7e96 to your computer and use it in GitHub Desktop.
Save rafacouto/a9e58598e7bbfe3b7e96 to your computer and use it in GitHub Desktop.
Energia sketch to test a light sensor connected to an operational amplifier. The circuit is powered by enabling the P1.6 signal during TEST_MILLIS every EVERY_MILLIS in order to safe energy (TEST_MILLIS/EVERY_MILLIS fraction).
// Energia sketch to test a light sensor connected to an operational amplifier. The circuit
// is powered by enabling the P1.6 signal during TEST_MILLIS every EVERY_MILLIS in
// order to safe energy (TEST_MILLIS/EVERY_MILLIS fraction).
#define POWER_LED GREEN_LED /* green LED (LED2 on board) and P1.6 connected to the Vdd */
#define SENSOR_LED RED_LED /* red LED (LED1 on board) */
#define SENSOR P1_7 /* pin P1.7 connected to Vout of the operational amplifier */
#define TEST_MILLIS 1 /* milliseconds that test is enabled */
#define EVERY_MILLIS 1000 /* milliseconds of the period of test */
void setup()
{
pinMode(POWER_LED, OUTPUT); // led is output
pinMode(SENSOR_LED, OUTPUT); // led is output
pinMode(SENSOR, INPUT); // sensor is input
}
void loop()
{
digitalWrite(POWER_LED, HIGH); // power on the test
delay(TEST_MILLIS); // wait while test is enabled
digitalWrite(SENSOR_LED, digitalRead(SENSOR)); // enable the sensor led when sensor input is enabled
digitalWrite(POWER_LED, LOW); // power off the test
delay(EVERY_MILLIS-TEST_MILLIS); // pause between tests
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment