一、成果影片
1.夜深人靜,用完電腦。只想上床睡覺。只要關燈,電腦就關機。
1.使用Arduino Leonardo
檔名:ProjectNo0001
內容:
#include <Keyboard.h>
/*
These core libraries allow the 32u4 and SAMD based boards
(Leonardo, Esplora, Zero, Due and MKR Family)
to appear as a native Mouse and/or Keyboard to a connected computer.
*/
void setup(){ // put your setup code here, to run once:
Keyboard.begin(); // initialize control over the keyboard
Keyboard.releaseAll();
}
void loop(){ // put your main code here, to run repeatedly:
if ( analogRead( A0 ) < 600 ) {
PcShutDown();
}
}
void PcShutDown() { //customised function
pinMode(4,INPUT_PULLUP); //make pin 4 an input and turn on the pullup resistor so it goes high unless connected to ground
if(digitalRead(4)==LOW){ // do nothing until pin 4 goes low
Keyboard.press(131); //the key to press (ASCII code)
}
pinMode(4,INPUT_PULLUP); //make pin 4 an input and turn on the pullup resistor so it goes high unless connected to ground
if(digitalRead(4)==LOW){ // do nothing until pin 4 goes low
Keyboard.press('r'); //the key to press (ASCII code)
}
Keyboard.releaseAll();
pinMode(4,INPUT_PULLUP); //make pin 4 an input and turn on the pullup resistor so it goes high unless connected to ground
if(digitalRead(4)==LOW){ // do nothing until pin 4 goes low
Keyboard.print("shutdown /s /f /t 0"); //Send the message
}
Keyboard.releaseAll();
pinMode(4,INPUT_PULLUP); //make pin 4 an input and turn on the pullup resistor so it goes high unless connected to ground
if(digitalRead(4)==LOW){ // do nothing until pin 4 goes low
Keyboard.press(176); //the key to press (ASCII code)
}
Keyboard.releaseAll();
delay( 5000 ); // waits a few milliseconds
}
資料來源:
1.【Arduino冷知識5】
1.【Arduino冷知識5】
2.Keyboard
3.
沒有留言:
張貼留言