Fatima Vunic
/
mbed_test
Test Programm
main.cpp@3:9be1093ae35e, 2020-01-13 (annotated)
- Committer:
- fatima365
- Date:
- Mon Jan 13 17:46:52 2020 +0000
- Revision:
- 3:9be1093ae35e
- Parent:
- 2:b43b5da6f341
- Child:
- 4:3c91e63e0642
4.Funkt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fatima365 | 0:7b78c5f07317 | 1 | #include "mbed.h" |
fatima365 | 0:7b78c5f07317 | 2 | #define BUTTON1 p14 // M3: push joystick pin |
fatima365 | 0:7b78c5f07317 | 3 | //#define BUTTON A1 // NUCLEO:Taster A1 |
fatima365 | 0:7b78c5f07317 | 4 | |
fatima365 | 0:7b78c5f07317 | 5 | //int modifybBit (int x, unsigned char position, bool State); |
fatima365 | 3:9be1093ae35e | 6 | int lauflicht (bool richtung, int time, int &anz); |
fatima365 | 1:b6f2a3f6e8eb | 7 | void nibbleLeds (int value); |
fatima365 | 2:b43b5da6f341 | 8 | void printb (uint8_t x); |
fatima365 | 0:7b78c5f07317 | 9 | |
fatima365 | 0:7b78c5f07317 | 10 | BusOut myleds(LED1, LED2, LED3, LED4); |
fatima365 | 0:7b78c5f07317 | 11 | DigitalIn button(BUTTON1); |
fatima365 | 0:7b78c5f07317 | 12 | |
fatima365 | 0:7b78c5f07317 | 13 | const int INIT = 0x03; |
fatima365 | 0:7b78c5f07317 | 14 | |
fatima365 | 0:7b78c5f07317 | 15 | int main() { |
fatima365 | 1:b6f2a3f6e8eb | 16 | int anzahl, anz; |
fatima365 | 1:b6f2a3f6e8eb | 17 | uint8_t value = INIT; |
fatima365 | 1:b6f2a3f6e8eb | 18 | |
fatima365 | 3:9be1093ae35e | 19 | anzahl = lauflicht(true, 400, anz=0); |
fatima365 | 3:9be1093ae35e | 20 | printf("anzahl = %d\n", anzahl); |
fatima365 | 3:9be1093ae35e | 21 | |
fatima365 | 1:b6f2a3f6e8eb | 22 | nibbleLeds(value); |
fatima365 | 1:b6f2a3f6e8eb | 23 | wait (0.1); |
fatima365 | 1:b6f2a3f6e8eb | 24 | } |
fatima365 | 3:9be1093ae35e | 25 | |
fatima365 | 3:9be1093ae35e | 26 | int lauflicht(bool richtung, int time, int &anz){ |
fatima365 | 3:9be1093ae35e | 27 | int i; |
fatima365 | 3:9be1093ae35e | 28 | uint8_t lauf = 0x01; |
fatima365 | 3:9be1093ae35e | 29 | |
fatima365 | 3:9be1093ae35e | 30 | if(!richtung) |
fatima365 | 3:9be1093ae35e | 31 | lauf = 0x08; |
fatima365 | 3:9be1093ae35e | 32 | |
fatima365 | 3:9be1093ae35e | 33 | while(1) { |
fatima365 | 3:9be1093ae35e | 34 | nibbleLeds(lauf&0x0F); |
fatima365 | 3:9be1093ae35e | 35 | if(richtung) { |
fatima365 | 3:9be1093ae35e | 36 | lauf = lauf << 1; |
fatima365 | 3:9be1093ae35e | 37 | if(lauf > 8) |
fatima365 | 3:9be1093ae35e | 38 | lauf = 0x01; |
fatima365 | 3:9be1093ae35e | 39 | } |
fatima365 | 3:9be1093ae35e | 40 | else { |
fatima365 | 3:9be1093ae35e | 41 | lauf = lauf >> 1; |
fatima365 | 3:9be1093ae35e | 42 | if(lauf == 0) |
fatima365 | 3:9be1093ae35e | 43 | lauf = 0x08; |
fatima365 | 3:9be1093ae35e | 44 | } |
fatima365 | 3:9be1093ae35e | 45 | if(button) |
fatima365 | 3:9be1093ae35e | 46 | break; |
fatima365 | 3:9be1093ae35e | 47 | wait_ms(time); |
fatima365 | 3:9be1093ae35e | 48 | anz++; |
fatima365 | 3:9be1093ae35e | 49 | } |
fatima365 | 3:9be1093ae35e | 50 | return anz; |
fatima365 | 3:9be1093ae35e | 51 | } |
fatima365 | 3:9be1093ae35e | 52 | |
fatima365 | 3:9be1093ae35e | 53 | |
fatima365 | 2:b43b5da6f341 | 54 | void printb (uint8_t x){ |
fatima365 | 2:b43b5da6f341 | 55 | for (int i = sizeof(x)<<3; i; i--) |
fatima365 | 2:b43b5da6f341 | 56 | putchar('0'+((x>>(i-1))&1)); |
fatima365 | 2:b43b5da6f341 | 57 | printf("\n"); |
fatima365 | 2:b43b5da6f341 | 58 | } |
fatima365 | 1:b6f2a3f6e8eb | 59 | |
fatima365 | 1:b6f2a3f6e8eb | 60 | void nibbleLeds(int value){ |
fatima365 | 1:b6f2a3f6e8eb | 61 | myleds = value%16; |
fatima365 | 1:b6f2a3f6e8eb | 62 | } |