Go Down

Topic: contamarce per moto (Read 198 times) previous topic - next topic

rikip98

Jul 17, 2014, 02:20 am Last Edit: Jul 17, 2014, 05:30 am by Coding Badly Reason: 1
salve a tutti sono uno nuovo di questo forum. ho comprato da poco arduino uno e vorrei iniziare a programmarlo . non e la prima volta che uso il linguaggio c+ , ma vorrei qualche consiglio da voi piu esperti di me su un progetto. il progetto riguarda di realizzare un contamarce per moto diciamo un po universale pensando a farlo funzionare con dei pulsanti; uno che "sale" la marcia e l'altro che "scende" gia qualcosina l'o fatta diciamo; su un display a 7 segmenti ora invece lo vorrei fare su un display lcd con collegamento di tipo seriale analogico; poi volevo mettere anche un'altro tasto che e quello della folla che al momento che si tiene premuto deve comparire sul display F e poi quando lo rilascio deve ritornare di nuovo a 1
il progetto che ho testato io e questo e funziona manca solo la folla
Code: [Select]

#define BUTTON_DOWN 11
#define BUTTON_UP 12

int ledPinA =  7;    // LED connected to digital pin 3
int ledPinB =  6;    // LED connected to digital pin 4
int ledPinC =  4;    // LED connected to digital pin 5
int ledPinD =  2;    // LED connected to digital pin 6
int ledPinE =  3;    // LED connected to digital pin 7
int ledPinF =  9;    // LED connected to digital pin 8
int ledPinG =  10;    // LED connected to digital pin 9
int ledPinP =  5;   // LED connected to digital pin 10

int val_down = 0;
int old_val_down = 0;
int val_up = 0;
int old_val_up = 0;
int state = 0;
int gear = 1;

// The setup() method runs once, when the sketch starts

void setup()   {            
 pinMode(BUTTON_DOWN, INPUT);
 pinMode(BUTTON_UP, INPUT);
 
 // initialize the digital pin as an output:
 pinMode(ledPinA, OUTPUT);
 pinMode(ledPinB, OUTPUT);
 pinMode(ledPinC, OUTPUT);
 pinMode(ledPinD, OUTPUT);
 pinMode(ledPinE, OUTPUT);
 pinMode(ledPinF, OUTPUT);
 pinMode(ledPinG, OUTPUT);  
 pinMode(ledPinP, OUTPUT);
 
 // initialize serial communication:
 Serial.begin(9600);
}

void led0()
{
 digitalWrite(ledPinA, HIGH);
 delay(50);
 digitalWrite(ledPinA, HIGH);
 delay(50);
 digitalWrite(ledPinB, HIGH);
 digitalWrite(ledPinC, LOW);
 digitalWrite(ledPinD, HIGH);
 digitalWrite(ledPinE, LOW);  
 digitalWrite(ledPinF, HIGH);  
 digitalWrite(ledPinG, LOW);
 digitalWrite(ledPinP, HIGH);
}

void led1()
{
 digitalWrite(ledPinA, HIGH);
 digitalWrite(ledPinB, LOW);
 delay(50);
 digitalWrite(ledPinB, LOW);
 delay(50);
 digitalWrite(ledPinC, LOW);
 digitalWrite(ledPinD, HIGH);
 digitalWrite(ledPinE, HIGH);  
 digitalWrite(ledPinF, HIGH);  
 digitalWrite(ledPinG, HIGH);
 digitalWrite(ledPinP, HIGH);
}

void led2()
{
 digitalWrite(ledPinA, LOW);
 digitalWrite(ledPinB, LOW);
 digitalWrite(ledPinC, HIGH);
 delay(50);
 digitalWrite(ledPinC, HIGH);
 delay(50);
 digitalWrite(ledPinD, LOW);
 digitalWrite(ledPinE, LOW);  
 digitalWrite(ledPinF, HIGH);  
 digitalWrite(ledPinG, LOW);
 digitalWrite(ledPinP, HIGH);
}

void led3()
{
 digitalWrite(ledPinA, LOW);
 digitalWrite(ledPinB, LOW);
 digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
 delay(50);
 digitalWrite(ledPinD, LOW);
 delay(50);
 digitalWrite(ledPinE, HIGH);  
 digitalWrite(ledPinF, HIGH);  
 digitalWrite(ledPinG, LOW);
 digitalWrite(ledPinP, HIGH);
}

void led4()
{
digitalWrite(ledPinA, HIGH);
 digitalWrite(ledPinB, LOW);
 digitalWrite(ledPinC, LOW);
 digitalWrite(ledPinD, HIGH);
 digitalWrite(ledPinE, HIGH);
 delay(50);
 digitalWrite(ledPinE, HIGH);
 delay(50);  
 digitalWrite(ledPinF, LOW);  
 digitalWrite(ledPinG, LOW);
 digitalWrite(ledPinP, HIGH);
}

void led5()
{
 digitalWrite(ledPinA, LOW);
 digitalWrite(ledPinB, HIGH);
 digitalWrite(ledPinC, LOW);
 digitalWrite(ledPinD, LOW);
 digitalWrite(ledPinE, HIGH);  
 digitalWrite(ledPinF, LOW);
 delay(50);
 digitalWrite(ledPinF, LOW);
 delay(50);
 digitalWrite(ledPinG, LOW);
 digitalWrite(ledPinP, HIGH);
}

void led6()
{
 digitalWrite(ledPinA, LOW);
 digitalWrite(ledPinB, HIGH);
 digitalWrite(ledPinC, LOW);
 digitalWrite(ledPinD, LOW);
 digitalWrite(ledPinE, LOW);  
 digitalWrite(ledPinF, LOW);  
 digitalWrite(ledPinG, LOW);
 delay(50);
 digitalWrite(ledPinG, LOW);
 delay(50);
 digitalWrite(ledPinP, HIGH);
}
void led7()
{
 digitalWrite(ledPinA, LOW);
 digitalWrite(ledPinB, LOW);
 digitalWrite(ledPinC, LOW);
 digitalWrite(ledPinD, LOW);
 digitalWrite(ledPinE, LOW);  
 digitalWrite(ledPinF, LOW);  
 digitalWrite(ledPinG, LOW);
 digitalWrite(ledPinP, HIGH);
 delay(50);
 digitalWrite(ledPinP, LOW);
 delay(50);

}



void setLed(int number)
{
 switch (number) {
   
   case 1:  
     led1();
     break;
   case 2:  
     led2();
     break;
   case 3:  
     led3();
     break;
   case 4:  
     led4();
     break;
   case 5:  
     led5();
     break;
   case 6:  
     led6();
     break;
   
     
   

 }
}
             
// the loop() method runs over and over again,
// as long as the Arduino has power

void oldloop()                    
{
                  // wait for a second
 led0();
 delay(1000);                  // wait for a second
 led1();
 delay(1000);                  // wait for a second
 led2();
 delay(1000);                  // wait for a second
 led3();
 delay(1000);                  // wait for a second
 led4();
 delay(1000);                  // wait for a second
 led5();
 delay(1000);                  // wait for a second
 led6();
 delay(1000);                  // wait for a second
 led7();
 delay(1000);                  // wait for a second
                  // wait for a second
}

void loop()
{
   val_up = digitalRead(BUTTON_UP);
   if ((val_up == HIGH) && (old_val_up == LOW)) {
     gear += 1;
     Serial.print("gear number:  ");
     Serial.println(gear, DEC);
     setLed(gear);
     delay(100);
   }
   old_val_up = val_up;

   val_down = digitalRead(BUTTON_DOWN);
   if ((val_down == HIGH) && (old_val_down == LOW)) {
     gear -= 1;
     Serial.print("gear number:  ");
     Serial.println(gear, DEC);
     setLed(gear);
     delay(100);
   }
   old_val_down = val_down;
   
   if (gear >= 6) {
     gear = 6;
   }
   if (gear <= 1) {
     gear = 1;
   }
   
   


}




aspetto le vostre risposte.
grazie anticipatamente per l'attenzione.

nid69ita

Ti invitiamo a presentarti (dicci quali conoscenze hai di elettronica e di programmazione) qui: Presentazioni
e a leggere il regolamento: Regolamento
- qui una serie di schede by xxxPighi per i collegamenti elettronici vari: ABC - Arduino Basic Connections
- qui le pinout delle varie schede by xxxPighi: Pinout
- qui una serie di link generali utili: Link Utili
my name is IGOR, not AIGOR

tapirinho

Ciao.
Non ho capito cosa ti serve...
Hai bisogno di aiuto per utilizzare l'LCD? O non sai come implementare la condizione che rileva la folle?

Go Up