Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- THere is other stuff to be put here, but for clarity I deleted it. You would need to put all that back in.
- */
- bool button_is_enabled = true;
- int button_check_interval = 500; // time is in milliseconds: this is the time interval that the button will be checked at.
- unsigned long buttonpress_begin_time = 0;
- unsigned long buttonpress_current_time = 0;
- bool servo_in_use = false; // If the servo is not in use at all, this variable allows totally skipping all the servo code.
- int servo_current_position = 0; // This is always set to where the servo is actually at.
- int servo_target_position = 0; // This is set to where you want the servo to end up at.
- bool servo_is_waiting = false;
- int servo_waiting_period = 25; // the servo's waiting time in milliseconds
- unsigned long servo_waiting_begin_time = 0;
- unsigned long servo_waiting_current_time = 0;
- // ,,,,,other stuff deleted also,,,,,,
- void setup() {
- Serial.begin(9600);
- //pinMode(buttonPin, INPUT_PULLUP); ---------- commented out, just because I removed the declaration
- //myservo.attach(sprinklerServo1); ---------- commented out, just because I removed the declaration
- }
- void loop() {
- //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- // The code section below only handles checking the button.
- // The button is only checked for a new value on the desired time interval.
- if (button_is_enabled == true) {
- updateButton();
- // also you would change button_is_enabled to false here, and record the current millis() time in buttonpress_begin_time
- }
- else {
- check_to_enable_button();
- }
- //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- // The code section below only handles operating the servo.
- if (servo_in_use == true) {
- if (servo_is_waiting == false) { // If this is false, then the servo can be moved.
- check_servo_position();
- // also you would change servo_is_waiting to true here, and record the current millis() time in servo_waiting_begin_time
- }
- else { // if servo_is_waiting == true , then this part checks if enough time has passed to allow moving the servo again
- check_to_enable_servo();
- }
- }
- //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- }
- void updateButton() {
- // code to get the new button reading is here
- // if button was pressed, then--
- // change servo_target_position to a different value
- // set servo_in_use to true
- }
- void check_to_enable_button() {
- // this is the code to re-enable the button if the button_check_interval time interval has passed
- // buttonpress_current_time = millis();
- // then compare buttonpress_begin_time to buttonpress_current_time to see if { button_check_interval } amount of time has passed
- // if it has, then re-enable the button so it gets checked again
- }
- void check_servo_position() {
- // this function is the one that changes the servo's position. this does not handle the servo's time delay.
- if (servo_current_position != servo_target_position) {
- // If the servo_current_position is not the same as the servo_target_position, then the servo needs to be moved still.
- change_servo_position();
- }
- else {
- // If servo_current_position is the same value as servo_target_position, then the servo is done moving and can be 'shut off'.
- servo_in_use = false;
- }
- }
- void change_servo_position() {
- // This is the fuction that would write a new PWM value to servo_current_position and then to the PWM pin, to change the servo's position.
- // The new PWM value would need to be closer to servo_target_position than the previous PWM value was.
- }
- void check_to_enable_servo() {
- // this function is the one for checking if the servo has been disabled long enough that it can be re-enabled (this handles the servo's time delay)
- // servo_waiting_current_time = millis();
- // then compare servo_waiting_begin_time to servo_waiting_current_time to see if { servo_waiting_period } amount of time has passed
- // if it has, then change servo_is_waiting to false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement