Étape 5: Le Code : Arduino
Nous avons accroché 4 interrupteurs à lame magnétique et 5 potentiomètres. Si vous avez ajouté d’autres/autres capteurs dans votre Arduino, vous devez les intégrer ce code en définissant quelles broches représentent les sondes et leur sortie puis via le port série à la fin.
Une dernière chose à noter : le fichier zip contient une esquisse de l’Arduino placée dans un dossier. Vous aurez besoin de cette hiérarchie de fichiers pour Arduino à l’esquisse se chargent correctement. Veuillez placer le fichier dans un dossier du même nom.
Code de l’Arduino :
/*
La cuisine polyphonique
Sara Montoro
Karl Landin
Alice Lee
Pitts de Noah
Université de Californie à Berkeley
CNM290/CS294-85
Fabrication de critique : Matériaux, protocoles et Culture
Laissez-nous un commentaire si vous avez d’autres idées et suggestions !
*/
mettre broche numérique (commutateur de mag)
const int mag1Pin = 4 ;
const int mag2Pin = 5 ;
const int mag3Pin = 6 ;
const int mag4Pin = 7 ;
mettre broche analogique (capteur de cap & pots)
const int capSensePin = A0 ;
const int pot1Pin = A1 ;
const int pot2Pin = A2 ;
const int pot3Pin = A3 ;
const int pot4Pin = A4 ;
const int pot5Pin = A5 ;
Set var (mag)
int mag1State, mag2State, mag3State, mag4State ;
Set var (pot)
capSense int = 0 ;
int pot1Val = 0 ;
int pot2Val = 0 ;
int pot3Val = 0 ;
int pot4Val = 0 ;
int pot5Val = 0 ;
void setup() {}
Démarrer la connexion série
Serial.Begin(9600) ;
configurer l’entrée numérique et permettre à la résistance de pull-up interne
pinMode (mag1Pin, INPUT_PULLUP) ;
pinMode (mag2Pin, INPUT_PULLUP) ;
pinMode (mag3Pin, INPUT_PULLUP) ;
pinMode (mag4Pin, INPUT_PULLUP) ;
}
void loop() {}
lire la valeur de l’aimant dans une variable
mag1State = digitalRead(mag1Pin) ;
mag2State = digitalRead(mag2Pin) ;
mag3State = digitalRead(mag3Pin) ;
mag4State = digitalRead(mag4Pin) ;
lire et mappez la valeur du pot dans une variable
pot1Val = analogRead(pot1Pin) ;
pot2Val = analogRead(pot2Pin) ;
pot3Val = analogRead(pot3Pin) ;
pot4Val = analogRead(pot4Pin) ;
pot5Val = analogRead(pot5Pin) ;
Envoyer à serial : capSense
Serial.Print(capSense) ;
Serial.Print(',') ;
Envoyer à serial : pot1
Serial.Print(pot1Val) ;
Serial.Print(',') ;
Envoyer à serial : pot2
Serial.Print(pot2Val) ;
Serial.Print(',') ;
Envoyer de série : pot4
Serial.Print(pot4Val) ;
Serial.Print(',') ;
Envoyer de série : pot5
Serial.Print(pot5Val) ;
Serial.Print(',') ;
Envoyer de série : pot3 ;
Serial.Print(pot3Val) ;
Serial.Print(',') ;
Envoyer à serial : mag1
Serial.Print(mag1State) ;
Serial.Print(',') ;
Envoyer à serial : mag2
Serial.Print(mag2State) ;
Serial.Print(',') ;
Envoyer à serial : mag3
Serial.Print(mag3State) ;
Serial.Print(',') ;
Envoyer à serial : mag4
Serial.Print(mag4State) ;
fin de ligne série avec * et commencer la nouvelle ligne
Serial.println('*') ;
}