Skocz do zawartości

Arduino IOT Cloud - conflicting declaration


Pomocna odpowiedź

Napisano

Hej,

postanowiłem się pobawić na IOT Cloud, siedzę i dumam, nie wiem w czym problem. Wrzuciłem kod do Arduino IDE z wyłączeniem bibliotek i danych do Cloud i dystans jest pokazywany, a na Cloud nie działa, mam taki błąd:

/tmp/2377963778/Untitled_feb09a/Untitled_feb09a.ino:20:6: error: conflicting declaration 'int distance'

int distance;

Kod ten znalazłem TU, jest podpowiedź, ale nie wiem gdzie to dodać.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/798422a4-cf2c-45fa-a3fb-fbf15d43a6c3 

  Arduino IoT Cloud Variables description

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

  int ultraSensor;

  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"
const int trigPin = 13;    
const int echoPin = 12;   
 long duration;  
 int distance; 



void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output  
  pinMode(echoPin, INPUT); // Sets the echoPin as an 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();
  digitalWrite(trigPin, LOW);  
 delayMicroseconds(2);  
 // Sets the trigPin on HIGH state for 10 micro seconds  
 digitalWrite(trigPin, HIGH);  
 delayMicroseconds(10);  
 digitalWrite(trigPin, LOW);  
 // Reads the echoPin, returns the sound wave travel time in microseconds  
 duration = pulseIn(echoPin, HIGH);  
 // Calculating the distance  
 distance = duration*0.034/2;  
 // Prints the distance on the Serial Monitor  
 Serial.println(distance);  
 delay(2000);

  }

 

Próbujesz przypisać do inta zmienną long. Dlatego krzyczy a w ogóle to okrutna nadmiarowość i zużycie zasobów 

(edytowany)

Zdefiniowałem zmienną o nazwie ultrasensor jako CloudLength i kompilacja przeszła. Jednak teraz jestem w miejscu, gdzie autor postu, czyli wyświetla wartości w monitorze, ale nie ma dashboardzie. Pewnie trzebe gdzieś podstawić to:

ultraSensor = distance;

Wstawiłem na koniec pętli i jest ok.

obraz.thumb.png.8f85cb0f899ed1a43e669c10d6fe9942.png

Edytowano przez Krisk

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...