"O'rnatish" turi yozilmaganmi?

'setup' turi nomini bildirmagan xatolarni ko'rsatishda davom etmoqda. Buni bekor qilishga urinib ko'rganman, kodni qayta yozish bilan bir qatorda, yana bir muammo paydo bo'ladi va bu muammoni qanday hal qilish kerakligini bilaman.

Ushbu dastur bir vaqtning o'zida 3 xil sensorlardan ma'lumotlarni to'playdi va turli xil hisob-kitoblarni ushbu alohida ko'chadan bajaradi va keyin jadvalga ketma-ket yoziladi va keyinchalik uni saqlab qo'yadi yoki eksport qiladi. Hozirgi kunda faqat bitta sensori ultratovushli sensori bo'lib, u masofani o'lchab, sirtdan o'lchaydi. (kodning so'nggi 2ta guruhida oddiy bosma funktsiyasi mavjud, shunda loop ishg'ol qilinadi)

Kodi:

#include 

long timeCounter;//milliseconds counter  
long timePassed;//The actual milliseconds time 
int trigPin = 2;
int echoPin = 3; 

long delay1 = 10;   //ms for cycle of event 1  
long delay2 = 5;    //ms for cycle of event 2  
long delay3 = 25;   //ms for cycle of event 3  
long delay4 = 10;

// Counters for the number of triggered events before the  
// corresponding event starts  
int countEvent1, countEvent2, countEvent3, countEvent4;  

int TRIGGER = 5;//ms to trigger the milliseconds timer  

int MAX1 = 2;//Number or triggered milliseconds to start event1  
int MAX2 = 1;//Number or triggered milliseconds to start event2  
int MAX3 = 5;//Number or triggered milliseconds to start event3  
int MAX4 = 2;

// Initialisation  
setup {  
     timeCounter = millis();//read the actual internal time  
     timePassed = 0;//we start with no time passed  

     countEvent1 = 0;  
     countEvent2 = 0;  
     countEvent3 = 0;
     countEvent4 = 0; 
} 

// Infinite cycle  
loop() {  

    //Read the actual time  
     timePassed = millis() - timeCounter;  
    //The smallest unit of time that should trigger an event is for event 2 (5 ms)  
    //so our trigger should count this smaller unit  

    //Check if the time passed after last reading is the trigger time  
     if(timePassed >= TRIGGER) {   
          if(++countEvent1 == MAX1){  
              //Reset the trigger and start the event  
               event1();  
               countEvent1 = 0;  
          }//Event 1   

         //It's time to manage the events  
          if(++countEvent2 == MAX2){  
              //Reset the trigger and start the event  
               event2();  
               countEvent2 = 0;  
          }//Event2 

         //It's time to manage the events  
          if(++countEvent3 == MAX3){  
              //Reset the trigger and start the event  
               event3();  
               countEvent3 = 0;  
          }//Event3

          if(++countEvent4 == MAX4){  
              //Reset the trigger and start the event  
               event4();  
               countEvent4 = 0;  
          }//Event4 

     }//Trigger 

}//LOOP  

// ============ Event functions ============== 

event1() {  
  long duration, distance;
  digitalWrite(trigPin,HIGH);
  delay(100);
  digitalWrite(trigPin, LOW);
  duration=pulseIn(echoPin, HIGH);
  distance =(duration/2)/29.1;
}  

event2() {  
Serial.print("work")
}  

event3() {   
Serial.print("work")
}  

Men kodlash uchun juda yangiman, shuning uchun kafolat bera oladigan bu erda yashirin ahmoqona xatolar bo'ladi.

2
Dasturlarni yozishdan oldin til sintaksisining asoslarini o'rganishingiz kerak ...
qo'shib qo'ydi muallif Majenko, manba
Faqat void setup dan keyin to'g'ri siljitishni unutasiz. Bu void setup() { bo'lishi kerak
qo'shib qo'ydi muallif Renato, manba

5 javoblar

Funktsiyaning ta'rifi bilan bog'liq muammolar mavjud. Misol bilan tushuntirib beray.

int kPinLed = 8;//LED - Pin 8

void setup()
{
  pinMode(kPinLed, OUTPUT);//LED as output
}

void loop()
{
  ledFun(); //Create LED Function
}

//Now write function's code with type, here "void"

void ledFun()
{
  digitalWrite(kPinLed, HIGH); //LED ON
  delay(1000);
  digitalWrite(kPinLed, LOW);  //LED OFF
  delay(1000);
}

Sizning kodingiz bilan bog'liq narsalar ham xuddi shunday. Faqat to'g'ri funksiyaning turini yozing. Umid qilamanki bu sizga yordam beradi.

3
qo'shib qo'ydi

Barcha funktsiyalaringiz (jumladan o'rnatish va pastadir) deklaratsiyani bajarish uchun bir turga kerak. Misol uchun:

event2() {  
Serial.print("work")
}  

Bo'lishi kerak:

void event2() {  
  Serial.print("work");
  }

Serial.print funktsiya chaqirig'idan keyin nuqta-vergulni ham eslatib o'ting.

asoslarini tushuntiruvchi sahifa mavjud.

Ushbu sahifada funktsiya deklaratsiyasining qanday ko'rinishini aniqlaydigan diagramma:

Function definitions

2
qo'shib qo'ydi

Funktsiya deklaratsiyasi turi bilan boshlanadi:

void setup() {

}

void loop() {

}

void funktsiya qiymatni qaytarmasligini anglatadi.

1
qo'shib qo'ydi

xatolikni sozlash turi mavjud emas. Men uni bekor qilishga harakat qildim

Buning to'g'ri yozilishi:

void setup(void) {
...
}

void loop(void) {
...
}
0
qo'shib qo'ydi

Ha, siz hech qachon ularni bekor qilishga muhtoj bo'lgan o'rnatish yoki pastadirni aniqlamagansiz.

void setup(){

}



void loop(){

} 
0
qo'shib qo'ydi