Advertisement
krzysp

virtuino IoT base unit program unit

Jan 5th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.10 KB | Source Code | 0 0
  1. void pin_to_app ();
  2. #define led_wew 2
  3. void setup_program()
  4. {
  5.   pinMode(led_wew, OUTPUT);
  6. }
  7.  
  8. void loop_program()
  9. {
  10.   pin_to_app ();
  11. }
  12.  
  13. //================ app -----> esp
  14.  
  15. void pin0_rec(String value) //LED in ESP
  16. {
  17.   int v = value.toInt();
  18.   if (v == 1) digitalWrite(led_wew, HIGH); else digitalWrite(led_wew, LOW);
  19. }
  20.  
  21. // //---Example 1: How to send a data to Virtuino app periodically
  22. int wsk_led = 0;
  23. void vLED_timer()  // esp -----> app every 2100 ms
  24. {
  25.   wsk_led = !wsk_led;
  26.   sendValue(pin12, String(wsk_led)); //esp ----> app
  27. }
  28.  
  29. void test() {       // esp -----> app every 3005 ms
  30.   int sensor = random(50);
  31.   sendValue(pin10, String(sensor));    
  32. }
  33.  
  34. void pin_to_app () {
  35.   //---Example 2: How to send a Digital Input state to Virtuino app every time it changes
  36.  
  37.   int pin11_val = 10;           // read the new state
  38.   if (pin11_lastValue != pin11_val) {         // compare with the previous input state
  39.     sendValue(pin11, String(pin11_val));  // send the new state esp ----> app
  40.     pin11_lastValue = pin11_val;              // copy the new state to variable pin0_lastValue
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement