Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- SoftwareSerial mySerial(10, 11); // RX, TX
- #define LED_PIN 13
- void setup() {
- pinMode(LED_PIN, OUTPUT);
- mySerial.begin(9600);
- }
- void loop() {
- if (mySerial.available()) {
- String inputString = mySerial.readString();
- if (inputString.indexOf("SONY") >= 0) {
- digitalWrite(LED_PIN, HIGH);
- mySerial.println("_Pictures");
- } else {
- digitalWrite(LED_PIN, LOW);
- }
- }
- }
- #include <windows.h>
- #include <stdio.h>
- int main() {
- HANDLE hCom;
- BOOL fSuccess;
- char *pszPortName = "COM3"; // COM-порт Arduino
- char *pszMessage = "SONY";
- DWORD dwNumBytesWritten = 0;
- DWORD dwNumBytesRead = 0;
- char inbuff[10];
- // Открываем COM-порт
- hCom = CreateFile(pszPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hCom == INVALID_HANDLE_VALUE) {
- printf("Failed to open COM: %dn", GetLastError());
- return 1;
- }
- // Отправляем сообщение
- fSuccess = WriteFile(hCom, pszMessage, strlen(pszMessage), &dwNumBytesWritten, NULL);
- if (!fSuccess) {
- printf("WriteFile failed: %dn", GetLastError());
- return 1;
- }
- // Получаем ответ
- fSuccess = ReadFile(hCom, inbuff, 10, &dwNumBytesRead, NULL);
- if (!fSuccess) {
- printf("ReadFile failed: %dn", GetLastError());
- return 1;
- }
- printf("Received: %sn", inbuff);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement