Little Bird Curriculum / code littlebird.com.au
eagled-night-3d.ino Arduino (C/C++) 21 lines · 0 views ✦ Open in English IDE Raw Download Embed view
const byte LIGHT_PIN = A9;
const byte LEFT_EYE = 3;
const byte RIGHT_EYE = 10;
const int DARK_BELOW = 300;
const int BRIGHT_ABOVE = 450;
bool eyesOn = false;
void setup() {
  pinMode(LEFT_EYE, OUTPUT);
  pinMode(RIGHT_EYE, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  int light = analogRead(LIGHT_PIN);
  if (light < DARK_BELOW) eyesOn = true;
  else if (light > BRIGHT_ABOVE) eyesOn = false;
  digitalWrite(LEFT_EYE, eyesOn ? HIGH : LOW);
  digitalWrite(RIGHT_EYE, eyesOn ? HIGH : LOW);
  Serial.print("light:"); Serial.print(light);
  Serial.print(",eyes:"); Serial.println(eyesOn ? 1 : 0);
  delay(50);
}

Embed this snippet

As an iframe:

Or drop it inline with a script tag (injects the highlighted block where included):

Shared from Little Bird Electronics curriculum.

Copied to clipboard