CCCPaste

"Wireless Control" rev_09

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: "Wireless Control"
	- Source Code NOT compiled for: Arduino Pro Mini 3.3V
	- Source Code created on: 2024-09-27 23:04:35

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* read and provide pot value via wifi */
/****** END SYSTEM REQUIREMENTS *****/


/********* User code review feedback **********
#### Feedback 1 ####
- add #include "keys.h" and relative source code with info about s
sid and password.
********* User code review feedback **********/

/****** DEFINITION OF LIBRARIES *****/
#include "keys.h"  // Include the keys.h file for WiFi credentials
#include   // Include AllThingsTalk WiFi SDK

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t pot_Potentiometer_Vout_PIN_A0 = A0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
auto wifiCreds = WifiCredentials(WIFI_SSID, WIFI_PASSWORD);  // Create WiFi credentials object
auto deviceCreds = DeviceConfig(DEVICE_ID, DEVICE_TOKEN);  // Create device credentials object
auto device = Device(wifiCreds, deviceCreds);  // Create device object

void setup(void)
{
    // Initialize serial communication
    Serial.begin(115200);
    
    // Initialize AllThingsTalk and WiFi connection
    device.init();  
    Serial.println("Setup complete. WiFi functionality initialized.");

    // Set the potentiometer pin as input
    pinMode(pot_Potentiometer_Vout_PIN_A0, INPUT);
}

void loop(void)
{
    // Read the potentiometer value
    int potValue = analogRead(pot_Potentiometer_Vout_PIN_A0);  // Read the analog value from the potentiometer
    
    // Send the potentiometer value to AllThingsTalk
    device.send("potentiometer_value", potValue);  // Send the potentiometer value to the specified asset on AllThingsTalk

    // Print the potentiometer value to the serial monitor
    Serial.print("Potentiometer Value: ");
    Serial.println(potValue);
    
    // Add a small delay to avoid flooding the serial output
    delay(1000);  // Delay for 1 second
}

/* END CODE */