/* * ChickenDoor.cpp Part 3 * * Created on: Jan 28, 2013 * Author: John */ /* * Requirements/Specs/Dreams/Whatever: * Close door at night, open door at sunrise. * Motor to move door can go forward and reverse. * Limit switches exist to detect opened and closed. */ /* * * Now we will fill in some things to make it compile and run, * So please read from the top down, and all the way to the * comments at the bottom :) */ void setup(){ // bzzt. Later. } void startMotorOpening(){ // Gee was it digitalPut or digitalSend or digi-something // To heck with it, i will just do this Serial.println("Starting Motor-Open phase"); } void startMotorClosing(){ // Hey this is easy Serial.println("Starting Motor-Close phase"); } void stopMotor(){ Serial.println("Stopping Motor"); } void startMotorWhichEverWayMakesSense(){ Serial.println("Trying to start Motor but I don't know") Serial.println("how to decide which way. Well tell the users it will be in v4 "); } bool sunriseDetected(){ // This will be really hard because I need to decide instantaneously // about something that occurs very slowly!! Serial.println("Trying to detect Sunrise"); } bool sunsetDetected(){ // whatever it is, it will probably be similar to the sunrise thing above Serial.println("Trying to detect Sunset"); } bool openedLimitDetected(){ // This might be pretty easy. Was it digi-Get or digi-pull digiRead or something? Serial.println("Trying to detect Opened Limit"); } bool closedLimitDetected(){ Serial.println("Trying to detect Closed Limit"); } bool manualButtonPushDetected(){ Serial.println("Milestone review: About the PushButton, Sorry Mr. Farmer/Sponsor, this is delayes to Phase 6"); Serial.println("It wasn't in the original spec, we just verbally *hinted* that we could do it."); } // No changes here to the important stuff: // (cool, I really like it when that happens. Robert Martin calls it // the Dependency Inversion Principle (well, similar anyway) void loop(){ if (sunriseDetected()) startMotorOpening(); if (sunsetDetected()) startMotorClosing(); if (openedLimitDetected()) stopMotor(); if (closedLimitDetected()) stopMotor(); if (manualButtonPushDetected()) startMotorWhichEverWayMakesSense(); } /* * Congrats! At this point it will compile and run! * In the corporate world we would declare done, milestone and budget met, * and Submit it to the Testers. * */