Problem mit Attiny und Serial.print

#3961221
Lesenswert?

Hallo,

Ich habe gestern das Kinderpiel Simon Sagt mal mit dem Attiny testen 
wollen. Arduino Uno kein Problem geht super. aber mit dem Attiny bekomme 
ich folgende Fehlermeldung.

1
Simon_Sagt.ino: In function ‘void setup()’:
2
Simon_Sagt.ino:25:3: error: ‘Serial’ was not declared in this scope
3
Simon_Sagt.ino: In function ‘void loop()’:
4
Simon_Sagt.ino:85:7: error: ‘Serial’ was not declared in this scope
5
void.ino: In function ‘void input()’:
6
void.ino:19:9: error: ‘Serial’ was not declared in this scope
7
void.ino:34:9: error: ‘Serial’ was not declared in this scope
8
void.ino:50:9: error: ‘Serial’ was not declared in this scope
9
void.ino:66:9: error: ‘Serial’ was not declared in this scope

Ok ist auch kein Problem dachte ich mir. Denn die Serial Ausgabe brauch 
ich ja nur zum testen.. also Alles rausgelöscht was Serial.print 
betrifft.. Auf dem Arduino läuft es immer noch ohne Probleme...
Aber auf dem Attiny4313 oder 2313 bekomme ich diese Fehlermeldung...
1
/usr/share/arduino/libraries/Tone/Tone.cpp: In member function ‘void Tone::begin(uint8_t)’:
2
/usr/share/arduino/libraries/Tone/Tone.cpp:141:9: error: ‘TCCR2A’ was not declared in this scope
3
         TCCR2A = 0;
4
         ^
5
/usr/share/arduino/libraries/Tone/Tone.cpp:142:9: error: ‘TCCR2B’ was not declared in this scope
6
         TCCR2B = 0;
7
         ^
8
In file included from /usr/share/arduino/libraries/Tone/Tone.cpp:28:0:
9
/usr/share/arduino/libraries/Tone/Tone.cpp:143:26: error: ‘WGM21’ was not declared in this scope
10
         bitWrite(TCCR2A, WGM21, 1);
11
                          ^
12
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:84:49: note: in definition of macro ‘bitSet’
13
 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
14
                                                 ^
15
/usr/share/arduino/libraries/Tone/Tone.cpp:143:9: note: in expansion of macro ‘bitWrite’
16
         bitWrite(TCCR2A, WGM21, 1);
17
         ^
18
/usr/share/arduino/libraries/Tone/Tone.cpp:144:26: error: ‘CS20’ was not declared in this scope
19
         bitWrite(TCCR2B, CS20, 1);
20
                          ^
21
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:84:49: note: in definition of macro ‘bitSet’
22
 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
23
                                                 ^
24
/usr/share/arduino/libraries/Tone/Tone.cpp:144:9: note: in expansion of macro ‘bitWrite’
25
         bitWrite(TCCR2B, CS20, 1);
26
         ^
27
/usr/share/arduino/libraries/Tone/Tone.cpp: In member function ‘void Tone::play(uint16_t, uint32_t)’:
28
/usr/share/arduino/libraries/Tone/Tone.cpp:248:9: error: ‘TCCR2B’ was not declared in this scope
29
         TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
30
         ^
31
/usr/share/arduino/libraries/Tone/Tone.cpp:306:9: error: ‘OCR2A’ was not declared in this scope
32
         OCR2A = ocr;
33
         ^
34
In file included from /usr/share/arduino/libraries/Tone/Tone.cpp:28:0:
35
/usr/share/arduino/libraries/Tone/Tone.cpp:308:18: error: ‘TIMSK2’ was not declared in this scope
36
         bitWrite(TIMSK2, OCIE2A, 1);
37
                  ^
38
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:84:30: note: in definition of macro ‘bitSet’
39
 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
40
                              ^
41
/usr/share/arduino/libraries/Tone/Tone.cpp:308:9: note: in expansion of macro ‘bitWrite’
42
         bitWrite(TIMSK2, OCIE2A, 1);
43
         ^
44
/usr/share/arduino/libraries/Tone/Tone.cpp:308:26: error: ‘OCIE2A’ was not declared in this scope
45
         bitWrite(TIMSK2, OCIE2A, 1);
46
                          ^
47
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:84:49: note: in definition of macro ‘bitSet’
48
 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
49
                                                 ^
50
/usr/share/arduino/libraries/Tone/Tone.cpp:308:9: note: in expansion of macro ‘bitWrite’
51
         bitWrite(TIMSK2, OCIE2A, 1);
52
         ^
53
/usr/share/arduino/libraries/Tone/Tone.cpp: In member function ‘void Tone::stop()’:
54
/usr/share/arduino/libraries/Tone/Tone.cpp:347:7: error: ‘TIMSK2’ was not declared in this scope
55
       TIMSK2 &= ~(1 << OCIE2A);
56
       ^
57
/usr/share/arduino/libraries/Tone/Tone.cpp:347:24: error: ‘OCIE2A’ was not declared in this scope
58
       TIMSK2 &= ~(1 << OCIE2A);
59
                        ^
60
/usr/share/arduino/libraries/Tone/Tone.cpp: In member function ‘bool Tone::isPlaying()’:
61
/usr/share/arduino/libraries/Tone/Tone.cpp:383:22: error: ‘TIMSK2’ was not declared in this scope
62
       returnvalue = (TIMSK2 & (1 << OCIE2A));
63
                      ^
64
/usr/share/arduino/libraries/Tone/Tone.cpp:383:37: error: ‘OCIE2A’ was not declared in this scope
65
       returnvalue = (TIMSK2 & (1 << OCIE2A));
66
                                     ^
67
/usr/share/arduino/libraries/Tone/Tone.cpp: In function ‘void TIMER2_COMPA_vect()’:
68
/usr/share/arduino/libraries/Tone/Tone.cpp:455:5: error: ‘TIMSK2’ was not declared in this scope
69
     TIMSK2 &= ~(1 << OCIE2A);                 // disable the interrupt
70
     ^
71
/usr/share/arduino/libraries/Tone/Tone.cpp:455:22: error: ‘OCIE2A’ was not declared in this scope
72
     TIMSK2 &= ~(1 << OCIE2A);                 // disable the interrupt
73
                      ^

hier ist auch noch mein Sketch
1
#include <Tone.h>
2
Tone speakerpin;
3
int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4};
4
int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100, 500};
5
int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5};
6
int duration[] = {100, 100, 100, 300, 100, 300};
7
boolean button[] = {2, 3, 4, 5}; //The four button input pins
8
boolean ledpin[] = {8, 9, 10, 11};  // LED pins
9
int turn = 0;  // turn counter
10
int buttonstate = 0;  // button state checker
11
int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far)
12
int inputArray[100]; 
13

14

15
void setup()
16
{
17

18
  speakerpin.begin(12); // Lautsprecher pin 12
19

20
  for(int x=0; x<4; x++)  // LED pins are outputs
21
  {
22
    pinMode(ledpin[x], OUTPUT);
23
  }
24
 
25
  for(int x=0; x<4; x++)
26
  {
27
    pinMode(button[x], INPUT);  // button pins are inputs
28
    digitalWrite(button[x], HIGH);  // enable internal pullup; buttons start in high position; logic reversed
29
  }
30

31
  randomSeed(analogRead(0)); //Added to generate "more randomness" with the randomArray for the output function
32
  for (int thisNote = 0; thisNote < 13; thisNote ++) {
33
     // play the next note:
34
     speakerpin.play(starttune[thisNote]);
35
     // hold the note:
36
     if (thisNote==0 || thisNote==2 || thisNote==4 || thisNote== 6)
37
     {
38
       digitalWrite(ledpin[0], HIGH);
39
     }
40
     if (thisNote==1 || thisNote==3 || thisNote==5 || thisNote== 7 || thisNote==9 || thisNote==11)
41
     {
42
       digitalWrite(ledpin[1], HIGH);
43
     }
44
     if (thisNote==8 || thisNote==12)
45
     {
46
       digitalWrite(ledpin[2], HIGH);
47
     } 
48
     if (thisNote==10)
49
     {  
50
       digitalWrite(ledpin[3], HIGH);
51
     }
52
     delay(duration2[thisNote]);
53
     // stop for the next note:
54
     speakerpin.stop();
55
     digitalWrite(ledpin[0], LOW);
56
     digitalWrite(ledpin[1], LOW);
57
     digitalWrite(ledpin[2], LOW);
58
     digitalWrite(ledpin[3], LOW);
59
     delay(25);
60
    }
61
  delay(1000);
62
}
63

64
void loop()
65
{  
66
  
67
 
68
   
69
    digitalWrite(ledpin[0], LOW);
70
    digitalWrite(ledpin[1], LOW);
71
    digitalWrite(ledpin[2], LOW);
72
    digitalWrite(ledpin[3], LOW);
73
    delay(1000);
74
 
75
    for (int y=turn; y <= turn; y++)
76
    { //Limited by the turn variable
77
 
78
      randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turn count
79
      for (int x=0; x <= turn; x++)
80
      {
81
       
82
     
83
        for(int y=0; y<4; y++)
84
        {
85
     
86
          if (randomArray[x] == 1 && ledpin[y] == 8)
87
          {  //if statements to display the stored values in the array
88
            digitalWrite(ledpin[y], HIGH);
89
            speakerpin.play(NOTE_G3, 100);
90
            delay(400);
91
            digitalWrite(ledpin[y], LOW);
92
            delay(100);
93
          }
94

95
          if (randomArray[x] == 2 && ledpin[y] == 9)
96
          {
97
            digitalWrite(ledpin[y], HIGH);
98
            speakerpin.play(NOTE_A3, 100);
99
            delay(400);
100
            digitalWrite(ledpin[y], LOW);
101
            delay(100);
102
          }
103
 
104
          if (randomArray[x] == 3 && ledpin[y] == 10)
105
          {
106
            digitalWrite(ledpin[y], HIGH);
107
            speakerpin.play(NOTE_B3, 100);
108
            delay(400);
109
            digitalWrite(ledpin[y], LOW);
110
            delay(100);
111
          }
112

113
          if (randomArray[x] == 4 && ledpin[y] == 11)
114
          {
115
            digitalWrite(ledpin[y], HIGH);
116
            speakerpin.play(NOTE_C4, 100);
117
            delay(400);
118
            digitalWrite(ledpin[y], LOW);
119
            delay(100);
120
          }
121
        }
122
      }
123
    }
124
    input();
125
  //}
126
}
127

128
void input() { //Function for allowing user input and checking input against the generated array
129

130
  for (int x=0; x <= turn;)
131
  { //Statement controlled by turn count
132

133
    for(int y=0; y<4; y++)
134
    {
135
     
136
      buttonstate = digitalRead(button[y]);
137
   
138
      if (buttonstate == LOW && button[y] == 2)
139
      { //Checking for button push
140
        digitalWrite(ledpin[0], HIGH);
141
        speakerpin.play(NOTE_G3, 100);
142
        delay(200);
143
        digitalWrite(ledpin[0], LOW);
144
        inputArray[x] = 1;
145
        delay(250);
146

147
        if (inputArray[x] != randomArray[x]) { //Checks value input by user and checks it against
148
          fail();                              //the value in the same spot on the generated array
149
        }                                      //The fail function is called if it does not match
150
        x++;
151
      }
152
       if (buttonstate == LOW && button[y] == 3)
153
      {
154
        digitalWrite(ledpin[1], HIGH);
155
        speakerpin.play(NOTE_A3, 100);
156
        delay(200);
157
        digitalWrite(ledpin[1], LOW);
158
        inputArray[x] = 2;
159
        delay(250);
160
   
161
        if (inputArray[x] != randomArray[x]) {
162
          fail();
163
        }
164
        x++;
165
      }
166

167
      if (buttonstate == LOW && button[y] == 4)
168
      {
169
        digitalWrite(ledpin[2], HIGH);
170
        speakerpin.play(NOTE_B3, 100);
171
        delay(200);
172
        digitalWrite(ledpin[2], LOW);
173
        inputArray[x] = 3;
174
        delay(250);
175

176
        if (inputArray[x] != randomArray[x]) {
177
          fail();
178
        }
179
        x++;
180
      }
181

182
      if (buttonstate == LOW && button[y] == 5)
183
      {
184
        digitalWrite(ledpin[3], HIGH);
185
        speakerpin.play(NOTE_C4, 100);
186
        delay(200);
187
        digitalWrite(ledpin[3], LOW);
188
        inputArray[x] = 4;
189
        delay(250);
190

191
        if (inputArray[x] != randomArray[x])
192
        {
193
          fail();
194
        }
195
        x++;
196
      }
197
    }
198
  }
199
  delay(500);
200
  turn++; //Increments the turn count, also the last action before starting the output function over again
201
}
202

203

204

205

206

207

208
void fail() { //Function used if the player fails to match the sequence
209

210
  for (int y=0; y<=2; y++)
211
  { //Flashes lights for failure
212
   
213
    digitalWrite(ledpin[0], HIGH);
214
    digitalWrite(ledpin[1], HIGH);
215
    digitalWrite(ledpin[2], HIGH);
216
    digitalWrite(ledpin[3], HIGH);
217
    speakerpin.play(NOTE_G3, 300);
218
    delay(200);
219
    digitalWrite(ledpin[0], LOW);
220
    digitalWrite(ledpin[1], LOW);
221
    digitalWrite(ledpin[2], LOW);
222
    digitalWrite(ledpin[3], LOW);
223
    speakerpin.play(NOTE_C3, 300);
224
    delay(200);
225
  }
226
  delay(500);
227
  turn = -1; //Resets turn value so the game starts over without need for a reset button
228
}
#3961240
Lesenswert?

1
/usr/share/arduino/libraries/Tone/Tone.cpp:141:9: error: ‘TCCR2A’ was not declared in this scope
2
         TCCR2A = 0;

Der 2313 hat keinen Timer 2 und daher sind auch die Peripherie Register 
bei dem Prozessor nicht definiert.

Die Modelle beim AVR Unterscheiden sich nicht nur im verfügbaren 
Speicher, sondern auch in der jeweiligen Peripherie (Ports, Timer, UART 
etc). Es gibt dann auch unterschiedliche Ausprägungen der der Peripherie 
(man kann mehr oder weniger einstellen/konfigurieren). Das macht das 
"Portieren" selbst innerhalb der AVRs nicht ganz trivial. Man muss sich 
die Datenblätter beider Modelle (Ausgangs-Modell, Ziel-Modell) anschauen 
und versuchen, die Funktion bestmöglich dort zum Laufen zu bringen.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren