ok
Dependencies: mbed ssd1306_library
Diff: main_Carte1.cpp
- Revision:
- 4:4f681e272268
- Parent:
- 3:03be0fb433da
- Child:
- 5:9c975d6bd219
diff -r 03be0fb433da -r 4f681e272268 main_Carte1.cpp --- a/main_Carte1.cpp Tue Feb 09 22:59:52 2021 +0000 +++ b/main_Carte1.cpp Wed Feb 10 14:50:41 2021 +0000 @@ -18,6 +18,8 @@ } TypeTrame; TypeTrame Trame; +SSD1306 OLED (I2C_SDA, I2C_SCL); // assumes default I2C address of 0x78 + /* typedef struct{ can_id_t id; @@ -31,22 +33,27 @@ DigitalOut ledD7(PA_6); DigitalOut ledD6(PA_7); -DigitalIn SW4_0(PA_1); -DigitalIn SW4_1(PA_3); +DigitalIn SW4_1(PA_1); +DigitalIn SW4_0(PA_3); InterruptIn SW1(PB_4, PullUp); InterruptIn SW2(PB_5, PullUp); InterruptIn SW3(PA_8, PullUp); +AnalogIn adc_RV1(PA_0); + CAN can(PA_11, PA_12); //Serial pc(USBTX, USBRX); +int value_SW4; // valeur 0,1,2,3 char Data[5] = "GEII"; /* Envoi d'une trame de donnees */ void AppuiSW1() { - if (can.write(CANMessage(2021, data, 5 , CANData, CANStandard))) { // Rmq : tableau = pointeur - ledD6 = !ledD6; + if (value_SW4 == 1) + { + if (can.write(CANMessage(2021, Data, 5 , CANData, CANStandard))) // Rmq : tableau = pointeur + ledD6 = !ledD6; } } @@ -59,14 +66,17 @@ int LectureSW4(){ int ETAT; - if (SW4_1 == 1) { - if (SW4_0 == 1) + int value_SW4_0 = SW4_0.read(); + int value_SW4_1 = SW4_1.read(); + + if (value_SW4_1 == 1) { + if (value_SW4_0 == 1) ETAT = 3; else ETAT = 2; } else { - if (SW4_0 == 1) + if (value_SW4_0 == 1) ETAT = 1; else ETAT = 0; @@ -77,30 +87,34 @@ int main() { //pc.baud(115200); + //pc.printf("Affichage serie\n"); + can.frequency(500000); - //pc.printf("main()\n"); - Etat = LectureSW4(); // valeur 0,1,2,3 //CANMessage msg; - //SW1.mode(PullUp); - //SW2.mode(PullUp); A mdoifier - //ledD9 = 1; - //ledD6 = 1; + + OLED.speed (SSD1306::Medium); // set working frequency + OLED.init(); // initialize SSD1306 + OLED.cls(); // clear frame buffer + OLED.locate (0,0); // set text cursor to line 3, column 1 + OLED.printf ("GEII"); // print to frame buffer + OLED.redraw(); // updates actual display transferring frame buffer over I2C bus SW1.fall(&AppuiSW1); - while(1) - { - //SW1.fall(&AppuiSW1); - //SW2.fall(&AppuiSW2); - /* - if(!SW2) //Detect Switch Press - { - //ledD8 = !ledD8; - ledD6 = !ledD6; - while(!SW2); //Wait for Key release - } - */ + { + value_SW4 = LectureSW4(); + OLED.locate (2,0); + OLED.printf("ADC A0=%2.1f", (adc_RV1.read()*100)); + //printf("ADC VRef = %f\n", adc_vref.read()); + OLED.locate (3,0); + OLED.printf("Valeur SW4_1=%d", SW4_0.read()); + OLED.locate (4,0); + OLED.printf("Valeur SW4_2=%d", SW4_1.read()); + OLED.locate (5,0); + OLED.printf("Valeur SW4=%d", value_SW4); + OLED.redraw(); + wait(1.0); } } \ No newline at end of file