Car simulation

Dependencies:   mbed

main.cpp

Committer:
sdzodan
Date:
17 months ago
Revision:
1:2b6bf3a52bc0
Parent:
0:80d1d58a91ab

File content as of revision 1:2b6bf3a52bc0:

#include "mbed.h"
int stanjeledice=0;
Ticker flipper1;
Serial pc(USBTX, USBRX);
AnalogIn Ain(p15);
float ADCdata;

DigitalIn sklopka(p8);

int rucna = 0;

void flip1()
{
    rucna = sklopka;
    ADCdata=Ain*8000;
    pc.printf("R=%d,b=%d,%.0f\n\r", rucna, stanjeledice,ADCdata);
}

InterruptIn shiftup(p6);

InterruptIn shiftdown(p7);

DigitalOut yellowled(p20);

DigitalOut redled(p19);


Timer debounce;

Timer debounce2;



DigitalOut ledica1(LED1);
DigitalOut ledica2(LED2);
DigitalOut ledica3(LED3);
DigitalOut ledica4(LED4);

void toggle(void);

void toggle2(void);

void toggle() {
if (debounce.read_ms()>200 && stanjeledice<=3)
stanjeledice=stanjeledice++;
debounce.reset(); 
}

void toggle2() {
if (debounce2.read_ms()>200 && stanjeledice>=1)
stanjeledice=stanjeledice--;
debounce2.reset(); 
}
    
    int main() {

flipper1.attach(&flip1, 0.5);

debounce.start();
debounce2.start();

shiftup.rise(&toggle);

shiftdown.rise(&toggle2);

while(1) {
    
            
    if (stanjeledice == 0){
     ledica1=0;
     ledica2=0;
     ledica3=0;
     ledica4=0;
     }
            
 else if (stanjeledice == 1){
     ledica1=1;
     ledica2=0;
     ledica3=0;
     ledica4=0;
     }
else if (stanjeledice == 2){
     ledica1=1;
     ledica2=1;
     ledica3=0;
     ledica4=0;
    }
    else if (stanjeledice == 3){
     ledica1=1;
     ledica2=1;
     ledica3=1;
     ledica4=0;
    }
    else if (stanjeledice == 4){
     ledica1=1;
//     ledica2=1;
     ledica3=1;
     ledica4=1;
    }
}
}