I have set up a project where by typing in the serial monitor my arduino will play a pattern of analog writes and delays through a simple DC motor. What I want to achieve is using something I made on p5.js which allows me to create a 10 step pattern of values, I want to be able to take the pattern as a Json put it on a micro sd card plug it in to arduino and have the arduino to play the json pattern on the micro sd card through the motor. I know I'll need to use ArduinoJSON but I have no idea where to start on actually getting the micro sd card adapter to work and on how to make the motor use the values from the json to play the pattern. Any help would be much appreciated.
int motorPin = 3;
void setup() {
Serial.begin(9600);
pinMode(motorPin, OUTPUT);
while (! Serial);
Serial.println("Speed 0 to 255");
}
void loop() {
String input = "";
while (Serial.available()){
input = Serial.readString();
delay(5);
}
/*if (Serial.available()) {
int speed = Serial.parseInt();
if (speed >= 50 && speed <= 255) {
analogWrite(motorPin, speed);
}*/
input.trim();
if (input == "Play"){
analogWrite(motorPin, 50);
delay(1000);
analogWrite(motorPin, 100);
delay(1000);
analogWrite(motorPin, 150);
delay(1000);
analogWrite(motorPin, 200);
delay(1000);
analogWrite(motorPin, 255);
delay(1000);
analogWrite(motorPin, 150);
delay(1000);
analogWrite(motorPin, 250);
delay(1000);
analogWrite(motorPin, 50);
delay(1000);
analogWrite(motorPin, 100);
delay(1000);
analogWrite(motorPin, 0);
}
else if (input == "255"){
analogWrite(motorPin, 255);
delay(10000);
analogWrite(motorPin, 0);
}
}
this is what I've got so far. It's disgustingly simple but I'm pretty new to arduino so am struggling with anything other that isn't simple atm.