Hey !
Thank you guys for your help
it works ! so much fun
below the code I'm going with, it is
for an interface with 6 faders and 1 joystick..
motors are hitting springs attached to home made percussions.
If you have any sugestions on how to improve..
I am reading!! it is still simple, and I will implement more controls and "musical" subdivisions etc
PS:I am 24years old, a bit retarded, I have Timmy's Syndrome
code:
#include <math.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
Adafruit_MotorShield AFMStop(0x61);
Adafruit_MotorShield AFMSbot(0x60);
Adafruit_DCMotor *myMotor1 = AFMSbot.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMSbot.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMSbot.getMotor(3);
Adafruit_DCMotor *myMotor4 = AFMSbot.getMotor(4);
Adafruit_DCMotor *myMotor5 = AFMStop.getMotor(1);
int potPin8 = A8;
int potPin9 = A9;
int potPin10 = A10;
int potPin11 = A11;
int potPin12 = A12;
int joyPinX = A13;
int joyPinY = A14;
int val8 = 0;
int val9 = 0;
int val10 = 0;
int val11= 0;
int val12 = 0;
int valX = 0;
int valY = 0;
void setup() {
AFMSbot.begin();
AFMStop.begin();
Serial.begin(9600);
}
void loop() {
joyPinX = analogRead(13) - 512;
joyPinY = analogRead(14) - 512;
int angle = (atan2(joyPinX, joyPinY));
double deg = atan2(joyPinX, joyPinY) * 57.295779513082320876798154814105;
Serial.println(deg);
if ((deg >=-10) && (deg<= 20)) {
myMotor1->setSpeed(potPin8);
myMotor1->run(FORWARD);
}
else if ((deg >=-100) && (deg<= -11)) {
myMotor2->setSpeed(potPin9);
myMotor2->run(FORWARD);
}
else if ((deg >=-180) && (deg<= -100)) {
myMotor3->setSpeed(potPin10);
myMotor3->run(FORWARD);
}
else if ((deg >=130) && (deg<= 160)) {
myMotor4->setSpeed(potPin11);
myMotor4->run(FORWARD);
}
else if ((deg >=30) && (deg<= 99)) {
myMotor5->setSpeed(potPin12);
myMotor5->run(FORWARD);
}
else {
myMotor1->setSpeed(0);
myMotor1->run(FORWARD);
myMotor2->setSpeed(0);
myMotor2->run(FORWARD);
myMotor3->setSpeed(0);
myMotor3->run(FORWARD);
myMotor4->setSpeed(0);
myMotor4->run(FORWARD);
myMotor5->setSpeed(0);
myMotor5->run(FORWARD);
}
}