Advertisement
dllbridge

For Arduino

May 9th, 2024
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. SoftwareSerial mySerial(10, 11); // RX, TX
  4. #define LED_PIN 13
  5.  
  6. void setup() {
  7.   pinMode(LED_PIN, OUTPUT);
  8.   mySerial.begin(9600);
  9. }
  10.  
  11. void loop() {
  12.   if (mySerial.available()) {
  13.     String inputString = mySerial.readString();
  14.     if (inputString.indexOf("SONY") >= 0) {
  15.       digitalWrite(LED_PIN, HIGH);
  16.       mySerial.println("_Pictures");
  17.     } else {
  18.       digitalWrite(LED_PIN, LOW);
  19.     }
  20.   }
  21. }
  22.  
  23.  
  24.  
  25. #include <windows.h>
  26. #include <stdio.h>
  27.  
  28. int main() {
  29.     HANDLE hCom;
  30.     BOOL fSuccess;
  31.     char *pszPortName = "COM3"; // COM-порт Arduino
  32.     char *pszMessage = "SONY";
  33.     DWORD dwNumBytesWritten = 0;
  34.     DWORD dwNumBytesRead = 0;
  35.     char inbuff[10];
  36.  
  37.     // Открываем COM-порт
  38.     hCom = CreateFile(pszPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  39.  
  40.     if (hCom == INVALID_HANDLE_VALUE) {
  41.         printf("Failed to open COM: %dn", GetLastError());
  42.         return 1;
  43.     }
  44.  
  45.     // Отправляем сообщение
  46.     fSuccess = WriteFile(hCom, pszMessage, strlen(pszMessage), &dwNumBytesWritten, NULL);
  47.  
  48.     if (!fSuccess) {
  49.         printf("WriteFile failed: %dn", GetLastError());
  50.         return 1;
  51.     }
  52.    
  53.     // Получаем ответ
  54.     fSuccess = ReadFile(hCom, inbuff, 10, &dwNumBytesRead, NULL);
  55.    
  56.     if (!fSuccess) {
  57.         printf("ReadFile failed: %dn", GetLastError());
  58.         return 1;
  59.     }
  60.     printf("Received: %sn", inbuff);
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement