this is my first stack overflow post and hope to not break anything.
I am currently trying to hook up my arduino micro to my cpp code. The point of the program is to seek if there are any certain color rgb pixels on the screen (240,130,208) and see within an x,y range. The problem is that when I try to import the windows library/api to my main.cpp code, it seems that the arduino ide spits out a compilation error,
Compilation error: windows.h: No such file or directory
I have tried to manually install the windows.h, and hook it up through the sketch tab. However, this leads me no where.
As you must know, I have to use the prebuilt c++ windows library in order to access my screen. All I need with the arduino micro is press the letter ‘k’ whenever the foundPixel() method returns true. Here are all my files
main.cpp:
#include "main.h"
// I need to add the #include <windows.h> without getting error
bool foundPixel(){
typedef WINAPI COLORREF (*GETPIXEL)(HDC, int, int);
int tolerance = 47;
// targetColor
int tC[3] = {240, 130, 208};
if(GetKeyState(VK_MENU) & 0x8000) {
HDC hdc = GetDC(NULL);
for(int x = (2560/2)-d; x<=(2560/2)+(d*2); x+=2) {
for(int y = (1440/2)-d; y<=(1440/2)+(d*2); y+=2) {
COLORREF color = GetPixel(hdc, x, y);
r = (int)GetRValue(color);
g = (int)GetGValue(color);
b = (int)GetBValue(color);
if(abs(r-tC[0]) <= tolerance && // red condition
abs(g-tC[1] <= tolerance && // green condition
abs(b-tC[2]) <= tolerance)) { // blue condition
return true;
}
}
}
}
return false;
}
project.ino:
#include "Keyboard.h"
#include "main.h"
void setup() {
//declare the buttons as input_pullup
pinMode(buttonPin, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
if(foundPixel()){
// do keyboard stroke
}
}
main.h:
#ifndef MAIN_H
#define MAIN_H
#include <windows.h>
bool foundPixel();
#endif
Thank you
I have tried to manually hook up all the windows.h related files through the sketch tab of arduino ide. However, no luck to properly hook up the windows api in my cpp file.
lmao ez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.