TestingA Posted May 19, 2020 Posted May 19, 2020 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: expandcollapse popup#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; } }
Developers Jos Posted May 19, 2020 Developers Posted May 19, 2020 Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states: Quote Share your cool AutoIt scripts, UDFs and applications with others. Do not post general support questions here, instead use the AutoIt Help and Support forums. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
argumentum Posted May 20, 2020 Posted May 20, 2020 #include <Misc.au3> While 1 If _IsPressed("1B") Then Exit ; 1B ESC key If _IsPressed("10") Then ; 10 SHIFT key ToolTip("- ON -") Else ToolTip("- OFF -") EndIf Sleep(100) WEnd ..it should work. Add the Sleep(100) or more. You're going too fast in your loop. TestingA 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
TestingA Posted May 20, 2020 Author Posted May 20, 2020 17 hours ago, argumentum said: #include <Misc.au3> While 1 If _IsPressed("1B") Then Exit ; 1B ESC key If _IsPressed("10") Then ; 10 SHIFT key ToolTip("- ON -") Else ToolTip("- OFF -") EndIf Sleep(100) WEnd ..it should work. Add the Sleep(100) or more. You're going too fast in your loop. Thank you, works perfect. 😇
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now