Script to turn LED on if pixel flashes yellow

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jezza
Posts: 3
Joined: 17 May 2022, 20:18

Script to turn LED on if pixel flashes yellow

Post by Jezza » 17 May 2022, 22:33

I am looking to have an LED turn on if a pixel on screen is flashing yellow
I want the LED to remain on if the pixel is flashing and turn off 2 seconds after it has stopped flashing (the 2 seconds is to ensure it is not going to flash again and turn off when not wanted)

I have a script that works :)
BUT when I duplicate it for a second LED and PIXEL the OFF function does not work

This is the working script:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

#SingleInstance Force

If DllCall("LoadLibrary", "str", "PacDrive32.dll")
If DllCall("PacDrive32.dll\PacInitialize")

#Persistent

;Turns LED off if pixel grey for 2seconds
CoordMode, Pixel
ticks := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
Sub1:
PixelGetColor, thisColor, -574, 327
If (thisColor != targetColor)
ticks := A_TickCount
SetTimer, Sub1, 100
If (A_TickCount - ticks > minTime)
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,0)

;Turns LED on if pixel flashes yellow
CoordMode, Pixel, Screen
Pixelgetcolor, Color9, -574, 327, RGB
if Color9 = 0xFFFF00
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,1)



This is when trying to add a second LED and PIXEL the OFF function does not work

If DllCall("LoadLibrary", "str", "PacDrive32.dll")
If DllCall("PacDrive32.dll\PacInitialize")

#Persistent

;Turns LED off if pixel grey for 2seconds

CoordMode, Pixel
ticks := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
Sub1:
PixelGetColor, thisColor, -574, 327
If (thisColor != targetColor)
ticks := A_TickCount
SetTimer, Sub1, 100
If (A_TickCount - ticks > minTime)
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,0)

;Turns LED on if pixel flashes yellow
CoordMode, Pixel, Screen
Pixelgetcolor, Color9, -574, 327, RGB
if Color9 = 0xFFFF00
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,1)

;Turns LED off if pixel grey for 2seconds
CoordMode, Pixel
ticks := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
Sub2:
PixelGetColor, thisColor, -652, 327
If (thisColor != targetColor)
ticks := A_TickCount
SetTimer, Sub2, 100
If (A_TickCount - ticks > minTime)
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,0)

;Turns LED on if pixel flashes yellow
CoordMode, Pixel, Screen
Pixelgetcolor, Color8, -652, 327, RGB
if Color8 = 0xFFFF00
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,1)
Last edited by Jezza on 20 May 2022, 09:42, edited 1 time in total.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Script to turn LED on if pixel flashes yellow

Post by BoBo » 17 May 2022, 23:23

@Jezza - the colored parts of the code can't be read if not viewed with the dark forum setting - and the code-line-tag/feature is lacking all the benefits of the standard code-section-tags. JFTR :)

Post Reply

Return to “Ask for Help (v1)”