I have a Teensy that I use for text input and I want it to keep alive the screen so it doesn't lock it out. I want my program to input a mouse movement every 14 minutes. But how do I count it and then have it move the mouse? ( I think millis() )Then have it wait, not with delay because it also is used to input text and the delay just makes it sit there and do nothing.
Love to hear your ideas please.
/* Buttons to USB Keyboard Example
You must select Keyboard from the "Tools > USB Type" menu
This example code is in the public domain.
*/
#include <Bounce.h>
// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10); // which is appropriate for
Bounce button3 = Bounce(3, 10); // most mechanical pushbuttons
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 10); // to rapid touch, you can
Bounce button7 = Bounce(7, 10); // increase this time.
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);
void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP); // Teensy++ LED, may need 1k resistor pullup
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
}
void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
{
/*
int i;
for (i=0; i<40; i++) {
Mouse.move(2, -1);
delay(25);
} */
// for (i=0; i<40; i++) {
// Mouse.move(2, 2);
// delay(25);
// }
// for (i=0; i<40; i++) {
// Mouse.move(-4, -1);
// delay(25);
// }
}
// Check each button for "falling" edge.
// Type a message on the Keyboard when each button presses
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button0.fallingEdge()) {
Keyboard.println("B0 press");
}
if (button1.fallingEdge()) {
Keyboard.println("B1 press");
}
if (button2.fallingEdge()) {
Keyboard.println("B2 press");
}
if (button3.fallingEdge()) {
Keyboard.println("B3 press");
}
if (button4.fallingEdge()) {
Keyboard.println("B4 press");
}
if (button5.fallingEdge()) {
Keyboard.println("B5 press");
}
if (button6.fallingEdge()) {
Keyboard.println("B6 press");
}
if (button7.fallingEdge()) {
Keyboard.println("B7 press");
}
if (button8.fallingEdge()) {
Keyboard.println("B8 press");
}
if (button9.fallingEdge()) {
Keyboard.println("MY TEXT HERE!");
}
// Check each button for "rising" edge
// Type a message on the Keyboard when each button releases.
// For many types of projects, you only care when the button
// is pressed and the release isn't needed.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
/* if (button0.risingEdge()) {
Keyboard.println("B0 release");
}
if (button1.risingEdge()) {
Keyboard.println("B1 release");
}
if (button2.risingEdge()) {
Keyboard.println("B2 release");
}
if (button3.risingEdge()) {
Keyboard.println("B3 release");
}
if (button4.risingEdge()) {
Keyboard.println("B4 release");
}
if (button5.risingEdge()) {
Keyboard.println("B5 release");
}
if (button6.risingEdge()) {
Keyboard.println("B6 release");
}
if (button7.risingEdge()) {
Keyboard.println("B7 release");
}
if (button8.risingEdge()) {
Keyboard.println("B8 release");
}
if (button9.risingEdge()) {
Keyboard.println("B9 release");
} */
}
/code]
Any time you find yourself doing the same thing repeatedly, you should consider doing it in a loop. Any time you find yourself creating similar variables that need to be numbered to tell them apart, you should consider using arrays. In this case the most obvious solution is to define an array of input pin numbers, and an array of objects to debounce them, and use a for loop to initialise them.
But this doesn't address your question. If you want the Arduino to send a mouse or keyboard event to your PC, then how are you going to stop it doing that while you're actually working on the PC? Wouldn't it be rather irritating to have your PC mouse move spontaneously or get spontaneous keyboard input that you weren't expecting?
As PaulS suggested - if you don't want the screen to lock then why don't you simply turn off the screen lock?
This was the very first thing I made when I got some Teensies, and it gets used routinely at our house using different laptops/netbooks plugged to the TV for netflix etc. I just leave it by the TV.
Some pc's the screensave/power managment settings don't work (Ubuntu)
Some pc's they are locked out by group policy (e.g. my company laptop)
For some of my kids they just find it easier to plug in the TV, plug in the Dongle
Why ask why?
Cheers,
John
(Ps moving a few pixels and then back every 10 minutes does not seem to interfere with normal mouse use, even if you forget to take it out )
Because it seems to me like a contrived solution to the problem and makes me think there has got to be a better way of solving the problem. Like, can't you find out how to configure Ubuntu to do what you want?
In the particular case of a works PC, locking down the screenlock settings might indicate that your employer has a policy that their PCs must not be left unattended and unlocked. If so, bypassing that for your own convenience would not be reasonable IMO, especially given the kids that you mentioned.
Actually the "Why ask Why" I intended to refer to "... my kids just plug in the dongle rather than reconfiguring their screensaver...", sorry.
On Ubuntu 10.04 and 12.04 LTS on my hardware the screensave/powermanagment has been broken, not just misconfigured. It has not been a big enough deal to me to warrant the linux research/patch/install cycle that would probably ensue...
It is not a breach of my company policy use my company-issued laptop for incidental personal use such as netflix/etc, or to use such a dongle while doing so. Anyone else should check their policies for detail, ymmv, etc...
I am not sure why folks need to nitpick. If I could change the settings I would. It's a company policy that irritates the living shit out of every user, but it remains unchanged. So there.
Can I configure the mouse movements as a function? But how do I get it to just move the mouse then wait for 14 minutes again?
Oh and I only am going to use 2-4 buttons, the rest will be deleted I think now that I look at it.
Antennas:
Can I configure the mouse movements as a function? But how do I get it to just move the mouse then wait for 14 minutes again?
You can use a function to carry out the mouse movements.
The pseudo code in post #5 does what you want. After moving the mouse, resetting timeStart begins the waiting process over again.
Do you know how to have the Arduino make the mouse move? If not, find out.
Once you have that working, write some code that does that every fourteen minutes. The 'blink without delay' sketch shows you how to do something at regular intervals while enabling other processing such as your button processing to continue in the background. I do suggest you tidy up that button handling code, though.
Thanks PeterH. I have made the mouse move, but it won't stop!! The mouse flies off down to the corner and stays there. It waits the 5 seconds, for testing, then the mouse stays down there moving. How do I stop it? I tried Mouse.end in two places but it doesn't work.
Can you explain your issue with the button code? If I can improve it with your help I will. It works right now and I will delete most of it as I am only going to use 2 buttons I think. That will hold the passwords I need.
Thank you.
Here is what I have now.....
#include <Bounce.h>
unsigned long wait = 0;
#define interval 5000
// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button7 = Bounce(7, 10);
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);
void setup() {
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
Mouse.begin();
}
void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button7.update();
button8.update();
button9.update();
if ((unsigned long)(millis()- wait) >= interval) // I am not so sure this is correct either, but it does wait 5 secs for now...
// Call the mouse to move
{
Mouse.move(2,2,0);
Mouse.end();
}
Mouse.end(); // STOP DAMN MOUSE (doesn't work)
// Check each button for "falling" edge.
// Type a message on the Keyboard when each button presses
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button8.fallingEdge()) {
Keyboard.println("B8 press");
}
if (button9.fallingEdge()) {
Keyboard.println("PASSWORD");
}
}/code]
Might be barking up the wrong tree here but I assume your Teensy is programmed through Teensyduino as native mouse example code does not use void setup() & void loop()
They have a mouse example here for the Teensyduino and from looking at it I think you need to do something like
// Call the mouse to move
{
Mouse.move(2,0); //Start mouse moving
delay(25);
Mouse.move(-2,0); //Move it back
delay(25);
Mouse.move(0,0); //Stop moving?
}
I'm not to sure about the last mouse.move(0,0) but I think it's needed else the mouse will just keep going.
Antennas:
Thanks PeterH. I have made the mouse move, but it won't stop!! The mouse flies off down to the corner and stays there. It waits the 5 seconds, for testing, then the mouse stays down there moving. How do I stop it? I tried Mouse.end in two places but it doesn't work.
I would expect the mouse to stop moving if the Arduino stops sending it mouse movement events.
I would expect the Mouse library to only send a mouse event when you call the API to send a mouse event.
Antennas:
Can you explain your issue with the button code? If I can improve it with your help I will. It works right now and I will delete most of it as I am only going to use 2 buttons I think. That will hold the passwords I need.
Please see my earlier comments about using arrays and loops instead of variables with numbers in their name and replicated code to deal with them all.
PeterH wrote...
I would expect the mouse to stop moving if the Arduino stops sending it mouse movement events.
I would expect the Mouse library to only send a mouse event when you call the API to send a mouse event.
......
That is all well and good.....Except I do not know how to do that. If I did I wouldn't have needed to ask why it won't stop moving.
It seems the problem lies in this bit of code...
if ((unsigned long)(millis()- wait) >= interval)
// Call the mouse to move
{
Mouse.move(8,8,0);
delay(25);
Mouse.move(0,0,0);
}
I don't think my code for the delay is right but I can't figure it out yet. I had wait set to 0 and interval to 5000 for testing. But if someone can help with a line that will wait an amount of time then move the mouse, then make it STOP. That would be wonderful and I can try and figure that out.
Or can someone post some code to go in there for the mouse and then explain it to me? So far I am still stuck. Oh and the mouse still wont stop moving.
timeNow is your millis() --> good
timeStart is your "wait" --> ok
14000 is your "interval" --> ok
Jiggle mouse is close --> needs work, see below
timeStart=timeNow --> need to add this, your equivalent would be wait=millis()
To Jiggle mouse:
Mouse.move(8,8);
delay(25);
Mouse.move(-8,-8); // move it back
Mouse.begin(), Mouse.end() not needed as far as I know.