Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


HPR1908: Arduino Pumpkin

Hosted by droops on 2015-11-25 00:00:00
Download or Listen

Code for Pumpkin

int ledPin1 = 5;
int ledPin2 = 6;
int motorPin = 8;
int lightPin = 3;
int lightVal;
int potPin = 0;
int potVal;

void setup(){
  Serial.begin(9600);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(motorPin, OUTPUT);
  pinMode(potPin, INPUT);
  pinMode(lightPin, INPUT);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(motorPin, LOW);
}

void loop(){
  potVal = analogRead(potPin);
  lightVal = analogRead(lightPin);
  Serial.println(lightVal);
  if (lightVal < potVal){
    animate();
  }
}

void animate(){
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(motorPin, HIGH);
  delay(100);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(motorPin, LOW);
}

Comments



More Information...


Copyright Information

Unless otherwise stated, our shows are released under a Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.

The HPR Website Design is released to the Public Domain.