yer sorry bout, my bad. This is the mario code (i sourced this from youtube)
i get an expected primary function before "for" error
int speakerPin = 13;
int button = 12;
int length = 295; // the number of notes
char notes[] = "EE E CE G g C g e a b ia gEGA FG E CDb C g e a b ia gEGA FG E CDb GNFR E uaC aCD GNFR E 1 11 GNFR E uaC aCD L D C CC C CD EC ag CC C CDE CC C CD EC ag EE E CE G g C g e a b ia gEGA FG E CDb C g e a b ia gEGA FG E CDb EC g u aF Fa bAAAGFEC ag EC g u aF Fa bF FFEDCe ec "; // a space represents a rest
float beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, //Page 1
2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 4, //Page 2
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, //Page4
1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, //Page 5
1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1.3, 1.3, 1.3, 1, 1, 1, 1, 1, 1, 2 }; //Page 6
int tempo = 95;
void playTone(int ton1, int duration) {
for (long i = 0; i < duration * 1000L; i += ton1) {
tone(speakerPin, ton1);
delayMicroseconds(ton1);
}
noTone(speakerPin);
}
void playNote(char note, int duration) {
// c c# d d# e f f# g g# a a# b
char names[] = { ' ', '!', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'i', 'N', 'R', 'u', '1', 'L', 'k'}; // [i = b flat] [N = G flat] [R = D#] [u = g#] [1 = C oct. 5] [L = E flat]
int tones[] = { 0, 1046, 138, 146, 155, 164, 174, 184, 195, 207, 220, 233, 246, 261, 293, 329, 349, 391, 440, 493, 523, 587, 659, 698, 783, 880, 987, 466, 740, 622, 415, 1046, 622u, 227};
// play the tone corresponding to the note name
for (int i = 0; i < 34; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(button, INPUT);
digitalWrite(button, HIGH);
}
void loop()
{
if (digitalRead(button) == LOW)
(
for(int i = 0; i < length; i++)
{
if (notes[i] == ' ')
{
delay(beats[i] * tempo); // rest
}
else
{
playNote(notes[i], beats[i] * tempo);
}
// pause between notes
delay(tempo / 2);
}
else if(digitalRead(button) == HIGH)
{
delay(100)
}
}
and here's the speaker code
#include "pitches.h"
#define Num_Notes 3
int pot = A0;
int speaker = 13;
int sensorValue = 0;
const int notes[Num_Notes] =
{
NOTE_E7, NOTE_E7, 0 };
const int beat[Num_Notes] =
{
1, 1, 4 };
const int beat_length = 300;
void setup() {
Serial.begin(9600);
pinMode(speaker, OUTPUT);
pinMode(pot, INPUT);
}
void loop()
{
sensorValue = analogRead(pot);
Serial.println(sensorValue);
int sensorReading = analogRead(A0);
if (sensorValue >= 400 && sensorValue <= 800)
{
tone(13, NOTE_C4, 2000);
}
else if (sensorValue >= 801 && sensorValue <= 820)
{
tone(13, NOTE_E7, 200);
delay (200);
tone(13, NOTE_E7, 200);
noTone (speaker);
}
delay(1);
}
any help or even points in the right direction would be great, it seems to be one thing to learn a specific range of functions but then applying them to other code seems to be another