Étape 4: Partie 3: conception de circuit et de programmation
#include < LiquidCrystal.h >
Innovente lcd (12, 11, 10, 5, 4, 3, 2) ; LCD sur les broches 12, 11, 10, 5, 4, 3, 2.
int StartPin = 9 ; entrée de l’interrupteur
int motor1Pin = 7 ; Pont en H Etape 1 (pin 2, 1 a)
int motor2Pin = 6 ; Pont en H Etape 2 (broche 7, 2 a)
int enablePin = 8 ; Pont en H activer pin
int DirPin = 13 ; Sélectionnez de la direction du moteur
int DirSwCounter = 0 ;
int LastDirState = 15 ;
int Dir = 14 ;
int cansCrushed ; Nombre initial de canettes écrasées à 0
void setup()
{
INITIALISER
pinMode (entrée, StartPin) ;
pinMode (entrée, DirPin) ;
pinMode (motor1Pin, sortie) ;
pinMode (motor2Pin, sortie) ;
pinMode (enablePin, sortie) ;
digitalWrite (enablePin, basse) ;
LCD.Begin (16, 2) ;
LCD.Print ("peut concasseur MKII") ;
Delay(3000) ;
LCD.Clear() ;
lcd.setCursor (0, 0) ;
LCD.Print("crushed:") ;
lcd.setCursor (10, 0) ;
LCD.Print((int)cansCrushed) ;
lcd.setCursor (0, 1) ;
LCD.Print("Weight:") ;
lcd.setCursor (9, 1) ;
LCD.Print((int)cansCrushed*.034375) ;
pinMode (entrée, StartPin) ;
pinMode (entrée, DirPin) ;
pinMode (motor1Pin, sortie) ;
pinMode (motor2Pin, sortie) ;
pinMode (enablePin, sortie) ;
digitalWrite (enablePin, basse) ;
cansCrushed = 0 ;
}
void loop()
{
LIRE LES PINS
int DirState = digitalRead(DirPin) ;
Si (LastDirState == LOW & & DirState == HIGH)
{
DirSwCounter ++ ;
}
LastDirState = DirState ;
PROCESSUS DE
Si (DirSwCounter % 2 == 0)
{
digitalWrite (Dir, faible) ;
cansCrushed ++ ;
} else {}
digitalWrite (Dir, élevé) ;
}
Si (digitalRead(StartPin) == HIGH & & digitalRead(Dir) == faible)
{
digitalWrite (enablePin, HIGH) ;
digitalWrite (motor1Pin, HIGH) ;
digitalWrite (motor2Pin, basse) ;
}
ElseIf (digitalRead(StartPin) == HIGH & & digitalRead(Dir) == HIGH)
{
digitalWrite (enablePin, HIGH) ;
digitalWrite (motor1Pin, basse) ;
digitalWrite (motor2Pin, HIGH) ;
} else {}
digitalWrite (enablePin, basse) ;
}
}
Ci-dessous le schéma de câblage pour la machine.
Pour ce modèle que j’ai utilisé Fritzing, c’est assez impressionnant.
http://www.fritzing.org
Construire le circuit imprimé de l’illustration, mais n’ajoutez pas encore les commutateurs.