// // OVERVIEW // This is a workup of the function "boolean is_flat" // // $Id: Checkout_Quick.ino,v 2.4 2016/11/20 13:13:16 gralimj1 Exp gralimj1 $ // $Source: /cygdrive/c/Users/gralimj1/Documents/Arduino/Checkout_Quick/RCS/Checkout_Quick.ino,v $ // const int tilt_sensor_a_pin = 7; const int red_led_pin = 10; void setup (void) { pinMode (tilt_sensor_a_pin, INPUT_PULLUP); pinMode(red_led_pin, OUTPUT); if (true) { Serial.begin (9600); }; // End "if (true)" }; // End "setup". void loop (void) { // This is a quick workup of the function "boolean is_flat" if (!is_flat ()) { Serial.println (" main: robot wrecked (fnma)"); }; // End "if (!is_flat)" Serial.println (" main: end of loop (gpbt)"); delay (2000); // For debugging purposes. }; // End "main loop". boolean is_flat (void) { // OVERVIEW: Sense the electrical contact tilt_sensor_a_pin. Return // "true" is the sensor is, at this instance, measuring the // Robot_Plane to be parallel to the Earth_Plane. Otherwise, return // "false". // // NOTE 20) This function assumes the following. // 20.10) The resistance of the Tilt_Sensor, when conducting, is // sufficiently low that the Arduio's "digitalRead" function will // reliably sense the conduction. const boolean red_led_is_tracking_sensor = true; // OVERVIEW: This is a debugging aid. The question: does the // engineer want to use the Red_Led to monitor the immediate status // of the Tilt_Sensor? Assumption_A: There is a sensor that // monitors, or perhaps simulates, the Tilt_Sensor. Assumption_B: // There is a Red_LED that the engineer can see. Assumption_C: The // Red_LED reports the status of the Tilt_Sensor. if (red_led_is_tracking_sensor) { digitalWrite (red_led_pin, LOW); }; // End "red_led_is_tracking_sensor" if (digitalRead (tilt_sensor_a_pin) == HIGH) { if (true) { Serial.println ("Debug: Robot_Plane parallel to Earth_Plane (49h7)"); }; // End "if (true)" if (true) { digitalWrite (red_led_pin, LOW); }; // End "if (true)" return (true); } // End " if (digitalRead...), "true" predicate else { if (true) { Serial.println ( "Debug: Robot_Plane not parallel to Earth_Plane (tk4n)"); }; // End "if (true)" if (true) { digitalWrite (red_led_pin, HIGH); }; // End "if (true)" return (false); }; // End "if (digitalRead...), "false" predicate }; // End "boolean is_flat"