Jump to content
Sign in to follow this  
BatMan22

Autoit Arduino Help

Recommended Posts

BatMan22

REVISED question:  Anyone know how to READ the led state below using the example below that I found?

 

#include <CommMG.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $CMPort = 9
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)

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("PC-2-Arduino", 199, 112, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE,"_ExitFunction")
$Group1 = GUICtrlCreateGroup("LED Pin-13", 8, 0, 185, 105)
$Button1 = GUICtrlCreateButton("Turn On / Off", 16, 16, 171, 41)
GUICtrlSetOnEvent($Button1,"LED_ON_OFF")
$Button2 = GUICtrlCreateButton("Blink 10 Times", 16, 56, 171, 41)
GUICtrlSetOnEvent($Button2,"LED_BLINK_10")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _ExitFunction()
     Exit
EndFunc

Func LED_ON_OFF()
_CommSendByte(1)
EndFunc

Func LED_BLINK_10()
_CommSendByte(2)
EndFunc

 

Arduino Code: 

char Address;
int LEDPIN = 5;
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;
  }

}

 

Edited by BatMan22

Share this post


Link to post
Share on other sites
AndyG
5 hours ago, BatMan22 said:

Anyone know how to READ the led state below using the example below that I found?

No.

 

But I wrote an Event-Mode-Sketch some time ago to control ports of the arduino directly from AutoIt without ( ! )  interfere with RUNNING ( ! ) arduino-scetches. 

https://autoit.de/index.php?thread/83954-autoit-und-arduino/&postID=671542#post671542

Share this post


Link to post
Share on other sites
BatMan22

For anyone who needs the answer to this, I posted an example in the examples forum. 

 

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×