Changes

Jump to: navigation, search

Split-flap display

305 bytes added, 22:37, 22 November 2013
The code is there (not pushed to any GIT):
<code> // Roue des minutes : // Engrenage moteur avec 4 aimants, capteur à effet Hall sur la PCB a la verticale // Il faut compter 79 passages pour faire un tour de flaps. Vérifier s'il y a une dérive. // Conclusion pour afficher le bon nombre : mapper 79*4 pas sur 62 positions (00->60 + blancs) // Tempo du moteur pas à pas#define tempo 14 #define SEC 10#define MIN 6#define HOR 2 unsigned int h = 0, m = 0, s = 0;unsigned int hM = 0, mM = 0, sM = 0; void setup() { // Define outputs for(int i=0; i<12; i++) pinMode(i+1, OUTPUT); Serial.begin(9600); Serial.setTimeout(30*1000);} void rot(unsigned char hms, unsigned int target){ // Demande invalide if((hms != SEC && hms != MIN && hms != HOR) || target > 60) { Serial.println("Incorrect !"); return; }
// Flap 00 > 29 : numérosTempo du moteur pas à pas // Flap 30 : blanc // Flap 31 > 60 : numéros-1 // Flap 61 : blanc  // Position actuelle unsigned int* current; if(hms == SEC) current = &s; else if(hms == MIN) current = &m; else current = &h;#define tempo 14
Serial.print("Position actuelle : ");#define SEC 10 Serial.println(*current);#define MIN 6 Serial.print("Target : "); Serial.println(target);  // Action ! // On flip les flaps tant qu'on est pas arrivé à destination Serial.print("Action sur les pins "); Serial.print(hms+3); Serial.print(", "); Serial.print(hms+#define HOR 2); Serial.print(", "); Serial.print(hms+1); Serial.print(", "); Serial.println(hms);
whileunsigned int h = 0, m = 0, s = 0; unsigned int hM = 0, mM = 0, sM = 0; void setup(*current !) { // Define outputs for(int i= 0; i<12; i++) pinMode(i+1, OUTPUT); Serial.begin(9600); Serial.setTimeout(30*1000); } void rot(unsigned char hms, unsigned int target)
{
// Demande invalide
if((hms != SEC && hms != MIN && hms != HOR) || target > 60)
{
Serial.println("Incorrect !");
return;
}
// Flap 00 > 29 : numéros
// Flap 30 : blanc
// Flap 31 > 60 : numéros-1
// Flap 61 : blanc
// Position actuelle
unsigned int* current;
if(hms == SEC) current = &s;
else if(hms == MIN) current = &m;
else current = &h;
Serial.print("Position actuelle : ");
int lol = Serial.println(*current); Serial.print("Target : "); Serial.println(target); // Action ! // On flip les flaps tant qu'on est pas arrivé à destination Serial.print("Action sur les pins "); Serial.print(hms+3); Serial.print(", "); Serial.print(hms+2); Serial.print(", "); Serial.print(hms+1); Serial.print(", "); Serial.println(lolhms);
forwhile(int i *current != 0; i<4; i++target)
{
Serial.print("Position actuelle : "); int lol = *current; Serial.println(lol); for(int i = 0; i<4; i++) { // Step 5 digitalWrite(hms+3, LOW); digitalWrite(hms+2, HIGH); digitalWrite(hms+1, LOW); digitalWrite(hms, HIGH); delay(tempo); // Step 7 digitalWrite(hms+3, HIGH); digitalWrite(hms+2, LOW); digitalWrite(hms+1, LOW); digitalWrite(hms, HIGH); delay(tempo); // Step 1 digitalWrite(hms+3, HIGH); digitalWrite(hms+2, LOW); digitalWrite(hms+1, HIGH); digitalWrite(hms, LOW); delay(tempo); // Step 3 digitalWrite(hms+3, LOW); digitalWrite(hms+2, HIGH); digitalWrite(hms+1, HIGH); digitalWrite(hms, LOW); delay(tempo); } // Demi-step pour faire tomber le flap, mais pas 2
digitalWrite(hms+3, LOW);
digitalWrite(hms+2, HIGH);
digitalWrite(hms+1, LOW);
digitalWrite(hms, HIGH);
delay(tempo);
// Step 7
digitalWrite(hms+3, HIGH);
digitalWrite(hms+2, LOW);
digitalWrite(hms+1, LOW);
digitalWrite(hms, HIGH);
delay(tempo);
 
// Step 1
digitalWrite(hms+3, HIGH);
digitalWrite(hms+2, LOW);
digitalWrite(hms+1, HIGH);
digitalWrite(hms, LOW);
delay(tempo*2); // Step 3 digitalWrite(hms+3, LOW*current); digitalWrite(hms+2, HIGH); digitalWrite(hms+1, HIGH); digitalWriteif(hms, LOW*current >= 61); delay(tempo) *current = 0;
}
// Demi-step pour faire tomber le flap, mais pas 2Stop motor
digitalWrite(hms+3, LOW);
digitalWrite(hms+2, HIGHLOW);
digitalWrite(hms+1, LOW);
digitalWrite(hms, LOW);
delay(tempo*2);  Serial.println(*current"Done")++; if(*current >= 61) *current = 0;
}
// Stop motor digitalWrite(hms+3, LOW); digitalWrite(hms+2, LOW); digitalWrite(hms+1, LOW); digitalWrite(hms, LOW); Serial.println("Done");} void loop() { if (Serial.available() > 0) { unsigned char b = Serial.read(); if(b == 'h' || b == 'm' || b == 's') { int roue; if(b == 'h') roue = HOR; else if(b = 'm') roue = MIN; else roue = SEC; Serial.print("Roue selectionnee : "); Serial.println(roue); int nb = Serial.parseInt(); Serial.println(nb); rot(roue,nb); } else if(b == 'w') { Serial.println("Give me 3 values !"); h = Serial.parseInt(); m = Serial.parseInt(); s = Serial.parseInt(); } else if(b == '+') { rot(MIN,m+1); }
}
}
}</code>
2
edits