Assignment #4: Discover Arduino

What I used

  • 6 LED and Tilt Sensor
  • Arduino
  • Manual Arduino StarterKit

I followed the project 8 of the starter manual of Arduino. In this tutorial is explained how to built a time tracker using a bunch of  led and a tilt sensor, a sensor that is like an Accelerometer, but less expensive and give less information (only up/down), in fact the Accelerometer is a tilt sensor it self.

The schema of the circuit that i followed was like this one:

arduino 08-01

IMG_20151217_161045IMG_20151217_161025IMG_20151217_161000

How It works

Each Led switch on every 1000 millisecond and when the Tilt sensor is hit all the lad that was switch on switch of .

IMG_20151217_150647IMG_20151217_150731IMG_20151217_150733

This is a snippet of the code :

void loop() {
unsigned long currentTime = millis();
 if(currentTime - prevTime > interval){
  prevTime = currentTime;
  digitalWrite(led,HIGH);
  led++;
  if(led==7){
   //doNothing
  }
 }
 switchState = digitalRead(switchPin);
 if(switchState != prevSwitchState ){
  for(int x=2; x<8;x++){
  digitalWrite(x,LOW);
  }
  led = 2;
  prevTime= currentTime;
 }
 prevSwitchState = switchState;
}

IMG_20151217_150123

Publicités
Publié dans Uncategorized