So basically i am trying to make a keytar, and I having some compiling issues.
Here is the error message and the code:
In file included from C:\Users\manue\Documents\Arduino\libraries\Bricktronics/Bricktronics.h:26:0,
from D:\arduino-1.8.19\sketch_jan20a\sketch_jan20a.ino:8:
C:\Users\manue\Documents\Arduino\libraries\Bricktronics/utility/digitalWriteFast.h:25:0: warning: "digitalPinToTimer" redefined
#define digitalPinToTimer(P) \
In file included from sketch\sketch_jan20a.ino.cpp:1:0:
C:\Users\manue\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/Arduino.h:180:0: note: this is the location of the previous definition
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
sketch_jan20a:48:16: error: expected constructor, destructor, or type conversion before '(' token
watch_for_input(note_duration, current_slot, false, true);
^
sketch_jan20a:49:7: error: expected constructor, destructor, or type conversion before '(' token
noTone(SPEAKER);
^
sketch_jan20a:50:16: error: expected constructor, destructor, or type conversion before '(' token
watch_for_input(rest_duration, current_slot, false, false);
^
D:\arduino-1.8.19\sketch_jan20a\sketch_jan20a.ino: In function 'void loop()':
sketch_jan20a:78:1: error: 'watch_for_input' was not declared in this scope
watch_for_input(note_duration, current_slot, false, true);
^~~~~~~~~~~~~~~
exit status 1
expected constructor, destructor, or type conversion before '(' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
<#include <Adafruit_MCP23017.h>
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>
#include <Bricktronics.h>
#include <Button.h>
#include <ColorSensor.h>
#include <Motor.h>
#include <Ultrasonic.h>
#include <Wire.h>
Bricktronics brick = Bricktronics();
Motor tone_knob = Motor(&brick, 1);
Motor duration_knob = Motor(&brick, 2);
Button mute_button = Button(&brick, 1);
#define SPEAKER 11
#define TONE_SLOT_0 6
#define TONE_SLOT_1 7
#define TONE_SLOT_2 A1
#define TONE_SLOT_3 A2
#define TONE_SLOT_4 A3
#define NUM_OF_SLOTS 5
char slot_button[] = {
TONE_SLOT_0,
TONE_SLOT_1,
TONE_SLOT_2,
TONE_SLOT_3,
TONE_SLOT_4};
int slot_frequency[] = {300, 400, 500, 600, 700};
int note_duration = 500;
int rest_duration = 100;
int current_slot = 0;
#define MIN_FREQUENCY 25
#define MIN_NOTE_DURATION 25
watch_for_input(note_duration, current_slot, false, true);
noTone(SPEAKER);
watch_for_input(rest_duration, current_slot, false, false);
void setup()
{
Serial.begin(115200);
Serial.println("Starting!");
brick.begin();
tone_knob.begin();
duration_knob.begin();
mute_button.begin();
for (char i = 0; i < NUM_OF_SLOTS; i++)
{
pinMode (slot_button[i], INPUT_PULLUP);
}
while (!mute_button.is_pressed()) {
//do nothing
}
}
void loop()
{
Serial.println(current_slot);
int current_frequency = slot_frequency[current_slot];
if (!mute_button.is_pressed())
{
tone(SPEAKER, current_frequency);
}
watch_for_input(note_duration, current_slot, false, true);
noTone(SPEAKER);
watch_for_input(rest_duration, current_slot, false, false);
current_slot += 1;
if (current_slot == NUM_OF_SLOTS)
{
current_slot = 0;
}
}
void watch_for_input(long ms, char slot, boolean in_slot,
boolean is_playing)
{
long start_time = millis();
long end_time = start_time + ms;
tone_knob.encoder->write(0);
duration_knob.encoder->write(0);
Serial.print("In slot:"); Serial.println(in_slot, DEC);
while (millis() < end_time)
{
if (!in_slot)
{
for (char i = 0; i < NUM_OF_SLOTS; i++)
{
if (digitalRead(slot_button[i]) == LOW)
{
Serial.print("Button pressed: ");
Serial.println(i, DEC);
handle_button_press(i);
}
}
}
long duration_change = duration_knob.encoder->read();
if (duration_change != 0)
{
Serial.print("duration knob: ");
Serial.println(duration_change, DEC);
if (in_slot)
{
note_duration += duration_change;
note_duration = max(note_duration, MIN_NOTE_DURATION);
}
else
{
rest_duration += duration_change;
rest_duration = max(rest_duration, 0);
}
end_time = millis();
duration_knob.encoder->write(0);
}
if (tone_knob.encoder->read() != 0)
{
Serial.print("Tone knob: ");
Serial.println(tone_knob.encoder->read(), DEC);
slot_frequency[slot] += (tone_knob.encoder->read());
slot_frequency[slot] = max(MIN_FREQUENCY, slot_frequency[slot]);
if (is_playing && !mute_button.is_pressed())
{
tone(SPEAKER, slot_frequency[slot]);
}
tone_knob.encoder->write(0);
}
}
}
void handle_button_press(char slot)
{
Serial.print("Handling button press for slot: ");
Serial.println(slot);
noTone(SPEAKER);
while (digitalRead(slot_button[slot]) == LOW)
{
tone(SPEAKER, slot_frequency[slot]);
watch_for_input(note_duration, slot, true, true);
noTone(SPEAKER);
watch_for_input(rest_duration, slot, true, false);
}
}