Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/14/2019 in all areas

  1. Hey guys, the code that I've written/borrowed below is mostly an example of using the commUDF listed at the bottom, just applied to an Arduino with accompanying Arduino code. Uses Serial communication to turn on a LED, then reads a response from the arduino and prints it in the console. I hope it helps Autoit Code: #include <CommMG.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> 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 1 ; Just use to call function, doesn't need to be a loop. LED_ON() Sleep(100) LED_OFF() Sleep(100) WEnd Func LED_ON() _CommSendString("1") ;Sends the Arduino a string of "1" to turn on LED Local $ret = _CommGetLine(@CR, 100, 100) ; Waits for up to 100 for a carriage return response from Arduino. ConsoleWrite($ret & @CRLF) ;Print to Console. EndFunc ;==>LED_ON_OFF Func LED_OFF() _CommSendString("0") ;Sends Arduino string of "0" to turn off the LED Local $ret = _CommGetLine(@CR, 100, 100) ; Waits for up to 100 for a carriage return response from Arduino. ConsoleWrite($ret & @CRLF) ;Print to Console. EndFunc ;==>LED_BLINK_10 Arduino Code: int led = 12; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(led, OUTPUT); } void loop() { // put your main code here, to run repeatedly: if (Serial.available()) { int data = Serial.read(); if (data == '1') //On { digitalWrite(led, HIGH); //writeslow(); Serial.print("The LED is on!"); } if (data == '0') //Off { digitalWrite(led, LOW); Serial.print("The LED is OFF!"); } } } Serial/Com port UDF this is all based on
    1 point
  2. as already specified in the script's comments: If you want to load jQuery from a disk file instead of directly download it from the web, use the following statement: $oScript.TextContent = FileRead(@ScriptDir & "\jquery.min.js") of course the jquery.min.js file must already be present in the same dir of the script
    1 point
  3. For a complete list of all allowed results: Local $s = "autoit" Local $a = _ArrayPermute(StringSplit($s & '-', "", 3)) Local $b = StringSplit(StringTrimRight(StringRegExpReplace(_ArrayToString($a, ',', 1) & ',', "((?<!\w|^)-\w+,|\w+-,)", ""), 1), ',', 3) $b = _ArrayUnique($b, 0, 0, 0, 0) _ArrayDisplay($b)
    1 point
  4. I think because the goal of 'random' was a misnomer. Hyphens could all be in the same position and that position still have been randomly selected each time. It is seeming more that you want: 1) the string shuffled 2) a random hyphen placed within the string (not before or after) 3) repeat steps 1 and 2 ensuring the results are all unique is that accurate? do you want the string shuffled every time around the loop?
    1 point
  5. nothing related to @youtuber request(randomness) but still.... #include <Array.au3> #include<string.au3> $a_String = 'word' $a_Array = StringSplit($a_String & '-', "", $STR_NOCOUNT) $a_suffel = _ArrayPermute($a_Array, '') _ArrayDelete($a_suffel, 0) _ArrayDisplay($a_suffel) ;$b_string = _ArrayToString($a_suffel) ;Msgbox(0,"", StringRegExpReplace($b_string , "\|(.*?)" , "" & @CRLF)) & not sure use of StringRegExpReplace is correct.
    1 point
  6. #include<string.au3> $str = "word" $insrt = "-" $sOut = "" for $i = 0 to stringlen($str) * 2 - 1 $sOut &= $i < stringlen($str) ? _StringInsert($str , $insrt , random(1 , stringlen($str))) & @LF : stringreverse(_StringInsert($str , $insrt , random(1 , stringlen($str)))) & @LF next msgbox(0, '' , $sOut) did you want them to be in unique positions. more shuffled than random? or really random? and did you want the reverse strings too? edit: i also assumed you didnt want the potential of a leading or trailing hyphen... edit: also, my bad i see now they are shuffled, not just reversed.
    1 point
  7. ? #include <array.au3> Local $sWord = 'word' Local $iNrWantedRandoms = 5, $iRandom, $sStrLen = StringLen($sWord) SRandom(@MSEC) ConsoleWrite('randomly place an hyphen' & @CRLF) For $i = 0 To $iNrWantedRandoms $iRandom = Random(1, $sStrLen - 1, 1) ConsoleWrite(StringLeft($sWord, $iRandom) & '-' & StringRight($sWord, $sStrLen - $iRandom) & @CRLF) Next ConsoleWrite("randomly place an hyphen and also shuffle word's letters" & @CRLF) Local $aWord = StringToASCIIArray($sWord) For $i = 0 To $iNrWantedRandoms _ArrayShuffle($aWord) $sRandomWord = StringFromASCIIArray($aWord) $iRandom = Random(1, $sStrLen - 1, 1) ConsoleWrite(StringLeft($sRandomWord, $iRandom) & '-' & StringRight($sRandomWord, $sStrLen - $iRandom) & @CRLF) Next
    1 point
  8. I use globals, else I may not bother to finish the program. I don't think globals are bad at all, and my local friends who argue that global is horrible programming practice, don't program anything. So their opinion is not valid to me. I am very clear that I can run into trouble with globals, but they can also save me time. EDIT: Namespace is the first problem using globals that comes to mind. I try to use local of course.
    1 point
  9. Imbuter2000, I really would not worry about it too much. The nature of AutoIt makes it difficult to avoid Global variables - so if you feel the need to use them then do so. Personally I would rather have legible code with some sensible Global variables than a psuedo-elegant web of parameters passed between functions - remember you are going to have to maintain this code in the future. Just try and avoid making every variable in the script Global in scope - that is not the way to go. M23
    1 point
×
×
  • Create New...