我在尝试编写的这段代码时遇到问题:



int ledStart = 30;

boolean commonHigh = true;

void setup() {
   Serial.begin(115200);
   SetTimer(0, 0, 10); // 10 seconds
   StartTimer();

   for (int i =0;i<9;++i) {
     pinMode (i, OUTPUT);
   }
   pinMode(9, INPUT);
}

int counter = 0;
bool go_by_switch = true;
int last_input_value = LOW;

void loop() {
    // put your main code here, to run repeatedly:

    number++;
    delay(1000);

    if(number>9)
        number=0; // If number is bigger than 9, then number is 0
}

//                0                   6
// pins           A   B  C  D  E   F  G
int ledpins[] = {12, 10, 7, 4, 2, 13, 8};
int pincnt = 7;
int number = 0;

int sevenseg[10][7] = {
// A, B, C, D, E, F, G
{1, 1, 1, 1, 1, 1, 0}, // A-F shall light. G shall not light.
{0, 1, 1, 0, 0, 0, 0}, // A shall not light. B and C shall light.

/*0*/
/*1*/
/*2*/
/*3*/
/*4*/
/*5*/
/*6*/
/*7*/
/*8*/

{1, 1, 1, 1, 1, 1, 1, 1}

if(go_by_switch) {
    int switch_input_value = digitalRead(9);
    if(last_input_value == LOW && switch_input_value == HIGH) {
        counter = (counter + 1) % 10;
    }

    last_input_value = switch_input_value;
}
else {
    delay(500);
    counter = (counter + 1) % 10;
}

writeNumber(counter);
}

for (int p=0; p<pincnt; p++) {
    pinMode (ledpins[P], OUTPUT);
    //It will count from 0 to smaller than 7. {12, 10, 7, 4, 2, 13, 8}; It will count from 0 to smaller than 7.
                                       //   0   1  2  3  4   5  6

    digitalWrite(ledpins[P], LOW);
}

for (int x=0; x<pincnt; x++); { //x is smaller than 7. The point is to bring out one of the patterns that will show on the display

    if (sevenseg[number][x]) // sevenseg = 7-segment display
        digitalWrite (ledpins[x], HIGH); // If it is 1, then there will be light.
    else
        digitalWrite (ledpins[x], LOW); // If it is 0, then there will not be light.


//   A
//F     B
//   G
//E     C
//   D





我收到的错误消息是:

_28.10.2015.ino:在函数'void setup()'中:

_28.10.2015.ino:7:20:错误:未在此范围内声明'SetTimer'

_28.10.2015.ino:8:14:错误:未在此范围内声明'StartTimer'

_28.10.2015.ino:在函数'void loop()'中:

_28.10.2015.ino:22:1:错误:未在此范围内声明'number'

_28.10.2015.ino:在全球范围内:

_28.10.2015.ino:52:1:错误:在'if'之前应为'}'

_28.10.2015.ino:52:1:错误:'int [7]'的初始化程序太多

_28.10.2015.ino:52:1:错误:预期为','或';'在“如果”之前

认为ve kompilering。

(Feil ved kompilering =编译时出错(挪威语)

最佳答案

问题是您没有在声明这些函数错误,也没有在声明“ number”变量。
您需要声明它们,例如:

int number;

void StartTimer( ){ // function code;}

或包含一个包含这些功能的“ .h”,如@Neil Locketz所说。

关于c++ - 未在此范围内声明-Arduino,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33392427/

10-09 03:04