Robotpirate Forums

Projects => ArduiNIX => Topic started by: Carnifex Maximus on April 10, 2011, 03:39:32 PM



Title: Set Buttons on ArduiNIX
Post by: Carnifex Maximus on April 10, 2011, 03:39:32 PM
I have been experimenting with the ArduiNIX sketch that I posted and I was wondering if anyone has tried using tactile switches to set the time. 

I have tried this using the following code, but no luck with it.

Quote
#define HourSet 0
#define MinsSet 2

{
  if (HourSet == 1);
  {
    lowerHours + 1;
  }
  
  if (MinsSet == 1);
  {
    lowerMins + 1;
  }


Does anyone have an idea what I'm doing wrong?


Title: Re: Set Buttons on ArduiNIX
Post by: Carnifex Maximus on April 15, 2011, 11:49:13 AM
My code for the switches is as follows.  I have tested this code, and it works reliably.  This code is for a 4 tube plus 2 dot clock.

#define HourSet A0 // Defines Hour Set Switch  Analog pin 0.
#define MinsSet A5 //  Defines Minute Set Switch. Analog pin 5.


void loop()     
{
  { 
  ////////////////////////////////////////
    if (digitalRead(HourSet) == 0)
    {
      clockHourSet++;
      delay(100);  //  Delay so the numbers do not change too quickly
    }
   
   
    if (digitalRead(MinsSet) == 0)
    {
      clockMinSet++;
      delay(100);
    }
  ////////////////////////////////////////
 
 
 }
 


Title: Re: Set Buttons on ArduiNIX
Post by: Carnifex Maximus on April 17, 2011, 03:58:32 PM
This code I wrote works, but adds an unwanted delay to the entire timekeeping operation.

I am currently working on writing a sketch without delay, so bear with me.


Title: Re: Set Buttons on ArduiNIX
Post by: nonentity on April 18, 2011, 07:32:42 AM
This code I wrote works, but adds an unwanted delay to the entire timekeeping operation.

I am currently working on writing a sketch without delay, so bear with me.

Great work!


Title: Re: Set Buttons on ArduiNIX
Post by: Liquidretro on April 19, 2011, 11:53:20 AM
I was wondering how I set the time on this.  I am going to build a custom enclosure for my clock so plugging it into USB wont really work.  Switches like this would be a great idea.  I am making a 6 tube clock myself.  How hard would it be to modify this code for that?  Also could there be a button to turn the tubes on and off?  My thought is to save tube life but still keep the time so I dont have to reset it if I unplugged it.  Has anyone done anything like this?


Title: Re: Set Buttons on ArduiNIX
Post by: Silvio Costigliolo on April 20, 2011, 07:21:19 AM
Hello, Liquidretro,

I


Title: Re: Set Buttons on ArduiNIX
Post by: catdotgif on April 23, 2011, 09:59:14 PM
My tact switch time set code, which includes debounce (so that erroneous 'bounce' clicks are not detected):
Code:
/**********Time Set Routine**********************/
boolean switchread = 1;
switchread = digitalRead(TIME_SET);
if (switchread == LOW) {
   while (switchread == LOW) {
     switchread = digitalRead(TIME_SET);
     }//do nothing while the switch is low
   delay(10);
   timeset = ((timeset + 1) % 4);
   }

//Set hours
if (timeset == 1) {
      //mask off everything but the hours
      NumberArray[2] = 999;
      NumberArray[3] = 999;
      NumberArray[4] = 999;
      NumberArray[5] = 999;

      boolean switchread = 1;
      switchread = digitalRead(TIME_UP);
      if (switchread == LOW) {
        while (switchread == LOW) {
          switchread = digitalRead(TIME_UP);
          }//do nothing while the switch is low
          delay(10);
        DateTime adjust (now.unixtime() + 3600); //set hours + 1
        RTC.adjust(adjust); // set to new time
        }
       
      switchread = digitalRead(TIME_DOWN);
      if (switchread == LOW) {
        while (switchread == LOW) {
          switchread = digitalRead(TIME_DOWN);
          }//do nothing while the switch is low
          delay(10);
        DateTime adjust (now.unixtime() - 3600); //set hours + 1
        RTC.adjust(adjust); // set to new time
        }
  }//end set hours
     
//Set minutes
if (timeset == 2) {
      //mask off everything but the minutes     
      NumberArray[0] = 999;
      NumberArray[1] = 999;
      NumberArray[4] = 999;
      NumberArray[5] = 999;

      boolean switchread = 1;
      switchread = digitalRead(TIME_UP);
      if (switchread == LOW) {
        while (switchread == LOW) {
          switchread = digitalRead(TIME_UP);
          }//do nothing while the switch is low
          delay(10);
        DateTime adjust (now.unixtime() + 60); //set mins + 1
        RTC.adjust(adjust); // set to new time
        }
       
      switchread = digitalRead(TIME_DOWN);
      if (switchread == LOW) {
        while (switchread == LOW) {
          switchread = digitalRead(TIME_DOWN);
          }//do nothing while the switch is low
          delay(10);
        DateTime adjust (now.unixtime() - 60); //set mins - 1
        RTC.adjust(adjust); // set to new time
        }
     
      }//end set minutes

//Set seconds
if (timeset == 3) {
      //mask off everything but the seconds
      NumberArray[0] = 999;
      NumberArray[1] = 999;
      NumberArray[2] = 999;
      NumberArray[3] = 999;

      boolean switchread = 1;
      switchread = digitalRead(TIME_UP);
      if (switchread == LOW) {
        while (switchread == LOW) {
          switchread = digitalRead(TIME_UP);
          }//do nothing while the switch is low
          delay(10);
        DateTime adjust (now.unixtime() + 1); //set seconds + 1
        RTC.adjust(adjust); // set to new time
        }
       
      switchread = digitalRead(TIME_DOWN);
      if (switchread == LOW) {
        while (switchread == LOW) {
          switchread = digitalRead(TIME_DOWN);
          }//do nothing while the switch is low
        delay(10);
        DateTime adjust (now.unixtime() - 2); //set seconds - 1
        RTC.adjust(adjust); // set to new time
        }
     
      }//end set hours






I use three switches.  The first enters 'time set' mode, and each time it is pressed it goes to set hours, minutes, and seconds, then exits time set mode.  The other two buttons increment and decrement.  It just lives in the main loop() statement.