Hallo iedereen
Project:
Ik wil onderstaande sketch op een attiny 25 programmeren.
Het project is van deze link: GitHub - adafruit/Adafruit_Brain-Machine-Kit: The Brain Machine Kit
Nu is het zo dat de code van de Brain-Machine niet als Sketch in arduino geschreven is.
Dus ik heb aan de code: “void setup() {“ en “void loop() {
// no need to repeat }” toegevoegd.
Probleem:
Ik krijg deze foutmelding:
Exit status 1
A function-definition is not allowed here before '{' token
Verdere info:
Instellingen van de Arduino UNO:
Board: Attiny 25/45/85
Processor: attiny 25
Clock internal 8 Mhz
Programmer: Arduino ISP
Bootloader is gebrand
Wat is hier het probleem?
Alvast bedankt voor de hulp.
Gr ben
```
**#include <avr/io.h> // this contains all the IO port definitions
#include <avr/interrupt.h> // definitions for interrupts
#include <avr/sleep.h> // definitions for power-down modes
#include <avr/pgmspace.h> // definitions or keeping constants in program memory
void setup() {
struct brainwaveElement {
char bwType; // 'a' for Alpha, 'b' for Beta, 't' for Theta, or 'd' for Delta ('0' signifies last entry in table
unsigned long int bwDuration; // Duration of this Brainwave Type (divide by 10,000 to get seconds)
} const brainwaveTab[] PROGMEM = {
{ 'b', 600000 },
{ 'a', 100000 },
{ 'b', 200000 },
{ 'a', 150000 },
{ 'b', 150000 },
{ 'a', 200000 },
{ 'b', 100000 },
{ 'a', 300000 },
{ 'b', 50000 },
{ 'a', 600000 },
{ 't', 100000 },
{ 'a', 300000 },
{ 't', 200000 },
{ 'a', 300000 },
{ 't', 300000 },
{ 'a', 150000 },
{ 't', 600000 },
{ 'a', 150000 },
{ 'b', 10000 },
{ 'a', 150000 },
{ 't', 600000 },
{ 'd', 10000 },
{ 't', 100000 },
{ 'd', 10000 },
{ 't', 100000 },
{ 'd', 10000 },
{ 't', 300000 },
{ 'a', 150000 },
{ 'b', 10000 },
{ 'a', 150000 },
{ 't', 300000 },
{ 'a', 150000 },
{ 'b', 10000 },
{ 'a', 200000 },
{ 'b', 50000 },
{ 'a', 200000 },
{ 'b', 150000 },
{ 'a', 150000 },
{ 'b', 200000 },
{ 'a', 100000 },
{ 'b', 250000 },
{ 'a', 50000 },
{ 'b', 600000 },
{ '0', 0 }
};
// This function delays the specified number of 1/10 milliseconds
void delay_one_tenth_ms(unsigned long int ms) {
unsigned long int timer;
const unsigned long int DelayCount=87; // this value was determined by trial and error
while (ms != 0) {
// Toggling PB5 is done here to force the compiler to do this loop, rather than optimize it away
for (timer=0; timer <= DelayCount; timer++) {PINB |= 0b0100000;};
ms--;
}
}
void blink_LEDs( unsigned long int duration, unsigned long int onTime, unsigned long int offTime) {
for (int i=0; i<(duration/(onTime+offTime)); i++) {
PORTB |= 0b00001100; // turn on LEDs at PB3, PB2
delay_one_tenth_ms(onTime); // for onTime
PORTB &= 0b11110011; // turn off LEDs at PB3, PB2
delay_one_tenth_ms(offTime); // for offTime
}
}
void do_brainwave_element(int index) {
char brainChr = pgm_read_byte(&brainwaveTab[index].bwType);
if (brainChr == 'b') {
// Beta
// start Timer1 with the correct Offset Frequency for a binaural beat for the Brainwave Type
// to Right ear speaker through output OC1A (PB1, pin 6)
OCR1C = 71; // T1 generates 217.014Hz, for a binaural beat of 16.7Hz
// delay for the time specified in the table while blinking the LEDs at the correct rate
// onTime = 30.0ms, offTime = 29.9ms --> 16.7Hz
blink_LEDs( pgm_read_dword(&brainwaveTab[index].bwDuration), 300, 299 );
return; // Beta
}
else if (brainChr == 'a') {
// Alpha
// start Timer1 with the correct Offset Frequency for a binaural beat for the Brainwave Type
// to Right ear speaker through output OC1A (PB1, pin 6)
OCR1C = 73; // T1 generates 211.149Hz, for a binaural beat of 10.8Hz
// delay for the time specified in the table while blinking the LEDs at the correct rate
// onTime = 46.2ms, offTime = 46.2ms --> 10.8Hz
blink_LEDs( pgm_read_dword(&brainwaveTab[index].bwDuration), 462, 462 );
return; // Alpha
}
else if (brainChr == 't') {
// PORTB &= 0b00001100; // (for debugging purposes only -- commented out for SLM)
// PORTB |= 0b00100000;
// Theta
// start Timer1 with the correct Offset Frequency for a binaural beat for the Brainwave Type
// to Right ear speaker through output OC1A (PB1, pin 6)
OCR1C = 75; // T1 generates 205.592Hz, for a binaural beat of 5.3Hz
// delay for the time specified in the table while blinking the LEDs at the correct rate
// onTime = 94.8ms, offTime = 94.9ms --> 5.3Hz
blink_LEDs( pgm_read_dword(&brainwaveTab[index].bwDuration), 948, 949 );
return; // Theta
}
else if (brainChr == 'd') {
// PORTB &= 0b00001100; // (for debugging purposes only -- commented out for SLM)
// PORTB |= 0b00010000;
// Delta
// start Timer1 with the correct Offset Frequency for a binaural beat for the Brainwave Type
// to Right ear speaker through output OC1A (PB1, pin 6)
OCR1C = 76; // T1 generates 202.521Hz, for a binaural beat of 2.6Hz
// delay for the time specified in the table while blinking the LEDs at the correct rate
// onTime = 1922ms, offTime = 1923ms --> 2.6Hz
blink_LEDs( pgm_read_dword(&brainwaveTab[index].bwDuration), 1922, 1923 );
return; // Delta
}
// this should never be executed, since we catch the end of table in the main loop
else {
// PORTB &= 0b00001100; // (for debugging purposes only -- commented out for SLM)
// PORTB |= 0b00000010;
return; // end of table
}
}
static volatile unsigned int power attribute ((section (".noinit")));
int main(void) {
if (power == 0) {
power = 1;
// Shut down everything and put the CPU to sleep
TCCR0B &= 0b11111000; // CS02:CS00=000 to stop Timer0 (turn off audio in Right ear speaker)
TCCR1 &= 0b11110000; // CS13:CS10=0000 to stop Timer1 (turn off audio in Left ear speaker)
MCUCR |= 0b00100000; // SE=1 (bit 5)
MCUCR |= 0b00010000; // SM1:0=10 to enable Power Down Sleep Mode (bits 4, 3)
delay_one_tenth_ms(10000); // wait 1 second
PORTB = 0x00; // turn off all PORTB outputs
DDRB = 0x00; // make PORTB all inputs
sleep_cpu(); // put CPU into Power Down Sleep Mode
}
power = 0;
TIMSK = 0x00;
DDRB = 0b00001111;
PORTB = 0x00;
TCCR0A = 0b01000010;
TCCR0B = 0b00000100;
OCR0A = 77;
TCCR1 = 0b10011001;
int j = 0;
while (pgm_read_byte(&brainwaveTab[j].bwType) != '0') { // '0' signifies end of table
do_brainwave_element(j);
j++;
}
TCCR0B &= 0b11111000;
TCCR1 &= 0b11110000;
MCUCR |= 0b00100000;
MCUCR |= 0b00010000;
delay_one_tenth_ms(10000);
PORTB = 0x00;
DDRB = 0x00;
sleep_cpu();
}
}
void loop() {
// no need to repeat
}
__```**__