Wink - idle mode

Share your awesome Ringo behaviors here!
Posts: 3
Joined: Sat Feb 06, 2016 4:04 am

Wink - idle mode

Postby Keith » Sat Feb 06, 2016 8:35 pm

This is a simple function that I wrote for Wink: it does nothing but blink the eyes.
I found this useful for Wink since it does not have an "off" switch, this makes it easy to keep it still while you are downloading code. It stops the motors and beeper, but keeps the eyes flashing so that it is easy to tell that the robot is on and operational.
When called, Idle will stay in a mode of blinking the eyes until the button is pressed. Arguments are time in milliseconds you want the eyes to blink on and off. I recommend 500, 500.

Code: Select all

Feb 2016 Keith kolb

  int onTime //millisconds of time you want eyes to be on
  int offTime //miliseconds of time you want eyes to be off
this function does nothing but blink eyes blue.
Used as an idle mode for when you don't want Wink going anywhere
eye blink lets you know it is operational
void Idle(int onTime, int offTime)
  unsigned long time = millis();//set up timer
  //cannot use delay function because it won't read buttonpress while delayed
  boolean on = false;//eyes start as off, this variable keeps track of eye state
  eyesOff();//turn eyes off
  motors(0,0);//turn motors off
  beepOff();//turn beeper off
  if(onTime > 3000){onTime = 3000;}//doesn't allow on time greater than 3 seconds
  if(offTime > 3000){offTime = 3000;}//doesn't allow off time greater than 3 seconds
  if(onTime < 100){onTime = 100;}//doesn't allow on time less than 0.1 seconds
  if(offTime < 100){offTime = 100;}//doesn't allow off less than 0.1 seconds
    if(on)//if eyes are in the on state
      if(millis()-time > onTime)//more time has passed than onTime
        eyesOff();//turn eyes off
        on = false;//set the on variable to false, signifing eyes are off
        time = millis();//reset timer
      }//end if
    }//end if
      if(millis()-time > offTime)
        eyesBlue(253);//turn eyes on
        on = true;//set the on variable to true, signifing eyes are on
        time = millis();//reset timer
      }//end if
    }//end else
    //if statement recycled from Wink_PreLoadedDemo_Rev01 functions to exit while loop
    if(buttonPressed()){                  //Exit this behavior if button is pressed
      motors(0,0);                        //make sure motors are stopped
      //changed i to k to insure compatability with code that has already declared i 2-6-2016 KMK
      for(int k=0;k<2;k++){
      break;  //break causes program to exit the while(1) loop
    }//end if
  }//end while
}//end function Idle

Posts: 2
Joined: Sat Feb 27, 2016 12:30 am

Re: Wink - idle mode

Postby Arnaud » Sat Feb 27, 2016 12:31 am

I think this post is in the wrong forum.

This forum is for Ringo, not wink :)

Posts: 32
Joined: Sun Feb 07, 2016 6:10 am

Re: Wink - idle mode

Postby wclift » Sat Feb 27, 2016 5:36 am

Nice! This fixes the very first problem I had with Wink. When I first tried to program it, I turned it on and it went into the PreLoaded routine. It surprised me, so pushed the "stop" button, and it did, and the charge light was still on, so I thought it was on. Couldn't download a program to it. It took me hours to realize my issue!

I like your routine. My first stab at this just used delays, and I just had to hold the button down until the delay occurred. I wasn't trying to blink though, so the loop was faster. I've imported your routine into my standard code package now. I whittled down the notify actions at the button press. Just turn lights off and beep once. I also like "randomEyes()" instead of eyesRed(), so I swapped that out! Thanks for the code sharing.

Who is online

Users browsing this forum: No registered users and 4 guests