/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/37024685-0e3c-4aa3-9c9e-1af1920ab2b7 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool botoeira;
  bool chave;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#define LED_BUILTIN 2
#define PINO4 4
#define potenciometro 34
int valores_pot = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(PINO4, INPUT);
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  valores_pot = analogRead(potenciometro);
  pot = map(valores_pot, 0, 4095, 0, 1023);
  
  if(digitalRead(PINO4) == HIGH){
  delay(100);
  botoeira=1;
 }
  else{
  botoeira=0;  
  }
  //se se quiser usar botoeira de 1 pulso
  //inserir o seguinte após delay 100 e apagar o restante e o else
  //botoeira = !botoeira;
}
 



/*
  Since Botoeira is READ_WRITE variable, onBotoeiraChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onBotoeiraChange()  {
  // Add your code here to act upon Botoeira change
  //bool botoeira = digitalRead(PINO4); 
  //Serial.println(flag);
}

/*
  Since Chave is READ_WRITE variable, onChaveChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onChaveChange()  {
  // Add your code here to act upon Chave change
  digitalWrite(LED_BUILTIN, chave);
}
$abcdeabcde151015202530fghijfghij