The needy bowl will freak out if you leave it. It will calm down when you come back but will take longer the longer you are away. Why do you tease this poor bowl?
int redPin = 11; int greenPin = 10; int bluePin = 9; int speakerPin = 5; int LED = 13; // Use the onboard Uno LED int isObstaclePin = 7; // This is our input pin int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE unsigned long goneTimeStart; unsigned long goneTimeStop; unsigned long totalTime; //uncomment this line if using a Common Anode LED //#define COMMON_ANODE void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); pinMode(speakerPin, OUTPUT); //Infrared setup pinMode(LED, OUTPUT); pinMode(isObstaclePin, INPUT); Serial.begin(9600); checkSensor(); } void loop() { checkSensor(); } void checkSensor() { isObstacle = digitalRead(isObstaclePin); Serial.println(isObstacle); if(isObstacle == HIGH){ comeBackPlease(); } } void comeBackPlease() { isObstacle = digitalRead(isObstaclePin); goneTimeStart = millis(); Serial.print("gone time start: "); Serial.println(goneTimeStart); while(isObstacle == HIGH){ //freak out! tone(5,3000,50); delay(100); tone(5,2000,50); delay(100); tone(5,1000,50); delay(100); if(digitalRead(isObstaclePin) == LOW){ calmDown(); break; } } } void calmDown() { goneTimeStop = millis(); Serial.print("gone time stop: "); Serial.println(goneTimeStop); totalTime = (goneTimeStop - goneTimeStart) / 50; //Run a loop in length compared to the total time away for (int i=totalTime; i >= 0; i--){ //If you remove your hand it will start complaining again. if(digitalRead(isObstaclePin) == HIGH) { comeBackPlease(); } //Loop through the total time and lower the pitch int thisTone = i + 400; tone(5,thisTone,50); delay(100); } noTone(5); }
Leave a Reply
You must be logged in to post a comment.