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:
- drummer
- Date:
- 2015-08-26
- Revision:
- 0:e939a25fbcad
- Child:
- 1:50fceb76f482
File content as of revision 0:e939a25fbcad:
#include "mbed.h"
//Zustände Lampen
#define VORNE_AUS 0
#define VORNE_LEUCHTEN 1
#define VORNE_BLINKEN 2
#define VORNE_BLINKENSCHNELL 3
#define HINTEN_AUS 0
#define HINTEN_LEUCHTEN 1
#define HINTEN_BLINKEN 2
#define ZUSTAND_MAX_VORNE 4
#define ZUSTAND_MAX_HINTEN 3
DigitalOut EnableP(PB_10);
PwmOut InP(PB_1);
DigitalOut EnableN(PB_11);
PwmOut InN(PA_6);
AnalogIn SpannungHallSensor(A0);
DigitalOut LampeVorne(PA_4);    //Scheinwerfer
DigitalOut LampeHinten(PA_5);
/*
DigitalOut EnableUSB(PB_12);
DigitalIn BremsTaster(PC_0);
AnalogIn SpannungBatterie(PB_0);
AnalogIn SpannungNachPMOS(PB_2);
Serial Bluetooth(SERIAL_TX, SERIAL_RX);
const int PMOS_Widerstand = 0.02;
*/
const int PERIODEN_DAUER = 10000;
    
float HallSensorWert(){
    float messung;
    messung = SpannungHallSensor.read() - 0.27; // read adc and rearange the voltage_value,because its 0.27 when the throttle is off
    
    if(messung < 0){          // meas0 isnt allowed to be <0 because its sets the pulsewidht of the pwm
        messung = 0;
    }
    
    messung *= 2;  // creates values between 0 and 1
    
    if(messung > 1){      // meas0 isnt allowed to be >1 because its sets the pulsewidth of the pwm 
        messung = 1;
    }
    
    return messung;
}
int ZustandVorne = 0;
int ZustandHinten = 0;
void LichtEinstellenVorne(int ZustandNeu) {
    while (ZustandVorne != ZustandNeu) {
        LampeVorne = 1;
        wait_ms(50);
        LampeVorne = 0;
        ZustandVorne++;
        if (ZustandVorne == ZUSTAND_MAX_VORNE) ZustandVorne = 0;
    }
}
    
void LichtEinstellenHinten(int ZustandNeu) {
    while (ZustandHinten != ZustandNeu) {
        LampeHinten = 1;
        wait_ms(50);
        LampeHinten = 0;
        ZustandHinten++;
        if (ZustandHinten == ZUSTAND_MAX_HINTEN) ZustandHinten = 0;
    }
}
int main() {
    EnableN = 1;
    InN.period_us(PERIODEN_DAUER);
    EnableP = 1;
    InP.period_us(PERIODEN_DAUER);
    
    while(1) {
        
        
       InP.pulsewidth_us(PERIODEN_DAUER*HallSensorWert());
       InN.pulsewidth_us(PERIODEN_DAUER*HallSensorWert());
       
       //InP.pulsewidth_us(PERIODEN_DAUER*0.5);
      //InN.pulsewidth_us(PERIODEN_DAUER*0.5);
       
       
       //LichtEinstellenVorne(VORNE_LEUCHTEN);
       //LichtEinstellenHinten(HINTEN_LEUCHTEN);
       
       //wait(5);
        
       // LichtEinstellenVorne(VORNE_BLINKENSCHNELL);
       //LichtEinstellenHinten(HINTEN_BLINKEN);
       
       //wait(5);
       
       // LichtEinstellenVorne(VORNE_AUS);
       //LichtEinstellenHinten(HINTEN_AUS);
       
      // wait(5);
        
    }
}