Homework - Mechanical Part

Johnparayno's picture

// Build a little weight to see if there is too much trash in my trashbin

 

 

int FSR = 4;   // the cell and 10K pulldown are connected to a0
int FSRREADING;   // the analog reading from the sensor divider
int LEDpin  = 6;     // Blue LED
int LEDbrightness;
 
unsigned int LEDpinVal  = 225;
   
int mySpeed = 10; // 50ms (.05 second) delay; shorten for faster fades
 
 
void setup(void) {      // We'll send debugging information via the Serial monitor
 
  pinMode(LEDpin,   OUTPUT);   // sets the pins as output
  Serial.begin(9600); 
}
 
void loop(void) {
  FSRREADING = analogRead(FSR); 
  
  Serial.println(FSRREADING); // the raw analog reading
  FSRREADING =  FSRREADING;
  
  //now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
  LEDbrightness = map(FSRREADING, 0, 1023, 0, 255);
 //added this to give output of photocell value
 
  if (FSRREADING < 50) {
    LEDpinVal  = (LEDpinVal - 1) % 255;
  }
        
  else if (FSRREADING > 120) {
    LEDpinVal  = (LEDpinVal + 1) % 255;
  }
    
  analogWrite(LEDpin,  LEDpinVal);  
  delay(mySpeed);
}
ass22.JPG
ass2.JPG
0
Your rating: None