Advertisement
pleasedontcode

"Wireless Control" rev_09

Sep 27th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Wireless Control"
  13.     - Source Code NOT compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2024-09-27 23:04:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read and provide pot value via wifi */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /********* User code review feedback **********
  25. #### Feedback 1 ####
  26. - add #include "keys.h" and relative source code with info about s
  27. sid and password.
  28. ********* User code review feedback **********/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include "keys.h"  // Include the keys.h file for WiFi credentials
  32. #include <AllThingsTalk_WiFi.h>  // Include AllThingsTalk WiFi SDK
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF ANALOG INPUT PINS *****/
  39. const uint8_t pot_Potentiometer_Vout_PIN_A0 = A0;
  40.  
  41. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  42. auto wifiCreds = WifiCredentials(WIFI_SSID, WIFI_PASSWORD);  // Create WiFi credentials object
  43. auto deviceCreds = DeviceConfig(DEVICE_ID, DEVICE_TOKEN);  // Create device credentials object
  44. auto device = Device(wifiCreds, deviceCreds);  // Create device object
  45.  
  46. void setup(void)
  47. {
  48.     // Initialize serial communication
  49.     Serial.begin(115200);
  50.    
  51.     // Initialize AllThingsTalk and WiFi connection
  52.     device.init();  
  53.     Serial.println("Setup complete. WiFi functionality initialized.");
  54.  
  55.     // Set the potentiometer pin as input
  56.     pinMode(pot_Potentiometer_Vout_PIN_A0, INPUT);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     // Read the potentiometer value
  62.     int potValue = analogRead(pot_Potentiometer_Vout_PIN_A0);  // Read the analog value from the potentiometer
  63.    
  64.     // Send the potentiometer value to AllThingsTalk
  65.     device.send("potentiometer_value", potValue);  // Send the potentiometer value to the specified asset on AllThingsTalk
  66.  
  67.     // Print the potentiometer value to the serial monitor
  68.     Serial.print("Potentiometer Value: ");
  69.     Serial.println(potValue);
  70.    
  71.     // Add a small delay to avoid flooding the serial output
  72.     delay(1000);  // Delay for 1 second
  73. }
  74.  
  75. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement