Truco estúpido de la mascota

My stupid pet trick used the photosensor to determine how many LED’s should be lit. Pretty simple concept, but I’m proud of myself for figuring out how to code it into the Arduino. Check out the video.

IMG_0076

Though I’m not sure how practical something like this is, I imagine we can come up with some cool ideas on how to extend this project in class. I was thinking:

-Auto-adjustment for darkness of an environment (think about how an iPhone can auto-adjust its brightness)

-LED variation based on a different input e.g. sound, number of tweets, weight in an elevator (this how amplifiers/receivers have LEDs that indicate decibel output of different parts of a sound)

Here is the nesty code:

int brightness;

void setup(){
  Serial.begin(9600);
  pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(3,OUTPUT);
}

void loop(){

 brightness = analogRead(A0);
 Serial.println(brightness);
 map(brightness,35,270,0,255);
 if(brightness<255){
   digitalWrite(11,HIGH);}
 if(brightness<205){
   digitalWrite(10,HIGH);}
 if(brightness<180){
   digitalWrite(9,HIGH);}
 if(brightness<160){
   digitalWrite(6,HIGH);}
 if(brightness<120){
   digitalWrite(5,HIGH);}
 if(brightness<100){
   digitalWrite(3,HIGH);}
 if(brightness>100){
    digitalWrite(3,LOW);}
 if(brightness>120){
    digitalWrite(5,LOW);}
 if(brightness>160){
    digitalWrite(6,LOW);}
 if(brightness>180){
    digitalWrite(9,LOW);}
 if(brightness>205){
    digitalWrite(10,LOW);}
 if(brightness>255){
    digitalWrite(11,LOW);}
 }

 

 

Leave a Reply