I was creating a project where the following part of the code reads certain area of the display(which i screen shared from mobile)
import cv2 as cv
import numpy as np
from PIL import ImageGrab
import serial
arduinodata = serial.Serial('com5',9600)
def led_on():
arduinodata.write(b'1')
def led_off():
arduinodata.write(b'0')
i=1
while True:
screen = np.array(ImageGrab.grab(bbox=(0,0,1920,1080)))
#define the screen resulation
screen_res = 1920, 1080
scale_width = screen_res[0] / screen.shape[1]
scale_height = screen_res[1] / screen.shape[0]
scale = min(scale_width, scale_height)
#resized window width and height
window_width = int(screen.shape[1] * scale)
window_height = int(screen.shape[0] * scale)
#cv.namedWindow('Resized Window', cv.WINDOW_NORMAL)
cv.resizeWindow('Resized Window', window_width, window_height)
resized = screen.resize()
health_bar = screen[262:268, 142:365]
health_grayed = cv.cvtColor(health_bar, cv.COLOR_BGR2GRAY)
count1 = cv.countNonZero(health_grayed)
if i==1:
e =count1
i=0
if e>count1:
led_on()
e=count1
if e<count1:
e=count1
and whenever the value of the count1 variable decreases i want the Arduino led should be turned on
this was the arduino code
char serialData;
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
Serial.begin(9600);
}
void loop()
// put your main code here, to run repeatedly:
{
if(Serial.available() >0)
{
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
}
}
But the led is turning on but does not turns off . I don't know why
can anyone please help me