Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- jdeschamps
- Date:
- 2020-05-04
- Revision:
- 5:0d73e455922a
- Parent:
- 4:2054aa78f3fd
File content as of revision 5:0d73e455922a:
#include "mbed.h"
#include "string.h"
Serial pc(USBTX, USBRX,9600); // tx, rx sur les broches associées au bus USB
DigitalOut led1(LED1);
DigitalOut brka (PTC4);
DigitalOut brkb (PTC12);
DigitalOut dira (PTD3);
DigitalOut dirb (PTD1);
DigitalOut pwma (PTD2);
InterruptIn sw3 (PTA4);
InterruptIn sw2 (PTC6);
char pas=1;
bool sens=0;
bool F;
unsigned int compteur=0;
char message[30];
int err;
int i=0;
int o=0;
Ticker mon_IT; // on associe l'interface Timeout à l'objet mon_IT
void Interruption_KBI1() {
i++;
printf("La valeur de i est de : %d \n", i);
pwma=0;
}
void Interruption_KBI2() {
o++;
printf("La valeur de o est de : %d \n", o);
pwma=0;
printf("Le nombre de pas est de : %d \n", compteur);
void Interruption_timer() {
if(sens==0)
{
pas++;
compteur++;
if(pas>8)pas=1;
}
if(sens==1)
{
pas--;
compteur--;
if(pas<1)pas=8;
}
if(compteur<=0){
pwma=0;
F=1;
}
switch (pas)
{
case 1:
brka=0;
dira=1;
brkb=1;
dirb=0;
break;
case 2:
brka=0;
dira=1;
brkb=0;
dirb=1;
break;
case 3:
brka=1;
dira=0;
brkb=0;
dirb=1;
break;
case 4:
brka=0;
dira=0;
brkb=0;
dirb=1;
break;
case 5:
brka=0;
dira=0;
brkb=1;
dirb=0;
break;
case 6:
brka=0;
dira=0;
brkb=0;
dirb=0;
break;
case 7:
brka=1;
dira=0;
brkb=0;
dirb=0;
break;
case 8:
brka=0;
dira=1;
brkb=0;
dirb=0;
break;
default:
break;
}
}
int main(void)
{
mon_IT.attach(&Interruption_timer,0.5); // l'interruption est associée au programme Interruption_timer et s'exécute toutes les 0.5s
// pour stopper mon_IT.detach();
sw3.rise(&Interruption_KBI1);
sw3.rise(&Interruption_KBI2);
while(1)
{
for(;;){
if (pc.readable()){
err=pc.scanf("%s",message);
if(strcmp(message,"monte_v1")==0)
{
sens=0; // marche avant
pwma=1;
}
else if(strcmp(message,"descend_v1")==0)
{
sens=1; // marche arriere
pwma=1;
}
else if(strcmp(message,"stop")==0)
{
pwma=0;
}
if (F==1)
{
printf("Fin de course");
F=0;
}
}
}
}
}