Urgency Alert

Using what we learned last class, I decided to use three red lights to alert the workers at the library when something needs to be checked out.  The idea is that when there are more items stacked in the box, or if there is just a heavy item, more of the red lights will light up letting the workers know.

The censor is undisturbed, indicating that nothing is in the box.
The censor is undisturbed, indicating that nothing is in the box.
One red light comes on.
One red light comes on.
Then the second.
Then the second.
Then the third!
Then the third!

IMG_4819

int brightness;
int green[] = {2,4,6};
int red[] = {13, 11, 9};

void setup(){
    //Green
    pinMode(2,OUTPUT);
    pinMode(4,OUTPUT);
    pinMode(6,OUTPUT);

    //Red
    pinMode(13,OUTPUT);
    pinMode(11,OUTPUT);
    pinMode(9,OUTPUT);

    Serial.begin(9600);
}//setup

void loop(){
    brightness = analogRead(A0);

    map(brightness, 0,255, 0, 255);

    //When the box is empty, green lights light up
    if(brightness>255){
        //Red:OFF
        for (int i=0; i<3; i++){
            digitalWrite(red[i],LOW);
        }
        //Green
        for (int i=0; i<3; i++){ 
            digitalWrite(green[i], HIGH); 
        } 
    } 

    //When there are periodicals, the green lights turn off and the red lights turn on 
    if(brightness >= 190 && brightness < 255){
        //Red
        for (int i=0; i<1; i++){
            digitalWrite(red[i], brightness);
        }
        //Green: OFF
        for (int i=0; i<3; i++){ 
            digitalWrite(green[i],LOW); } 
        } 

        if(brightness >= 100 && brightness < 190){
            //Red
            for (int i=0; i<2; i++){
                digitalWrite(red[i],brightness);
            }
            //Green: OFF
            for (int i=0; i<3; i++){ 
                digitalWrite(green[i],LOW); 
            } 
        } 

        if(brightness >= 0 && brightness < 100){
            //Red
            for (int i=0; i<3; i++){
                digitalWrite(red[i],brightness);
            }
            //Green: OFF
            for (int i=0; i<3; i++){
                digitalWrite(green[i],LOW);
            }
        }
}//loop

 

Leave a Reply