Projet rampe arduino

Fonctionnement

 

Code Arduino

#define Switch_in   2       // Entrée du switch 
#define PWM_out 9 // Sortie PWM
#define N 300 // A faire varié en fonction de la pente
#define Pas_us 10 // Pas en µS


int valSwitch=0; // 0-1

void setup()
{
pinMode(Switch_in, INPUT);
pinMode(PWM_out, OUTPUT);
digitalWrite(PWM_out, LOW);
}

void loop()
{

// Lecture du switch
while((valSwitch=digitalRead(Switch_in))==0);


// Génération de la rampe
while(valSwitch==1)
{

// Montée
for(int n=0;n<N;n++)
{
digitalWrite(PWM_out, HIGH); delayMicroseconds(n*Pas_us);
digitalWrite(PWM_out, LOW); delayMicroseconds((N-n)*Pas_us);
}

// Descente
for(int n=N;n>0;n--)
{
digitalWrite(PWM_out, HIGH); delayMicroseconds(n*Pas_us);
digitalWrite(PWM_out, LOW); delayMicroseconds((N-n)*Pas_us);
}

digitalWrite(PWM_out, LOW);
while((valSwitch=digitalRead(Switch_in))!=0);
delay(2000);
}
}
Click to rate this post!
[Total: 1 Average: 5]

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

FPGA | Arduino | Matlab | Cours will use the information you provide on this form to be in touch with you and to provide updates and marketing.