Hi,
can anyone help me please? i wan't to know how do i use "_IsPressed" with arduino.
My AutoIT script doesn't work when i press Shift key. Im using ELEGOO UNO R3 Mikrocontroller Board ATmega328P ATMEGA16U2
AutoIT Code:
#include <CommMG.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
$hDLL = DllOpen("user32.dll")
;Conncet to Arduino
Global $CMPort = 3
Global $CmBoBaud = 9600
Global $sportSetError = ''
Global $CmboDataBits = 8
Global $CmBoParity = "none"
Global $CmBoStop = 1
Global $setflow = 2
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
If @error Then
MsgBox(16,"Error!","Can't connect to Arduino on port - "&$CMPort)
Exit
EndIf
_CommSetRTS(0)
_CommSetDTR(0)
While True
If _IsPressed("10", $hDLL) Then
LED_BLINK_10() ;If Shift is pressed call Func.
EndIf
WEnd
Func _ExitFunction()
Exit
DllClose("user32.dll")
EndFunc
Func LED_ON_OFF()
_CommSendByte(1)
EndFunc
Func LED_BLINK_10()
_CommSendByte(2) ;Blink 10 Times
EndFunc
Arduino code:
char Address;
int LEDPIN = 13;
int LEDSTATE = 0;
void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("Waiting for data...\n");
pinMode(LEDPIN, OUTPUT);
digitalWrite(LEDPIN, LOW);
}
void loop()
{
while (Serial.available() > 0)
{
Address = Serial.read();
if (Address == 1) ONOFF();
if (Address == 2) BLINK();
}
}
void ONOFF()
{
if(LEDSTATE == 0) { //if is pressed
digitalWrite(LEDPIN, HIGH);
LEDSTATE = 1;
} else { //if not pressed
digitalWrite(LEDPIN, LOW);
LEDSTATE = 0;
}
}
void BLINK()
{
for (int i=0; i <= 9; i++){
digitalWrite(LEDPIN, LOW);
digitalWrite(LEDPIN, HIGH);
delay(100);
digitalWrite(LEDPIN, LOW);
delay(100);
}
if(LEDSTATE == 1) { //if is pressed
digitalWrite(LEDPIN, HIGH);
LEDSTATE = 1;
} else { //if not pressed
digitalWrite(LEDPIN, LOW);
LEDSTATE = 0;
}
}