test program

Dependencies:   mbed

Committer:
shogu
Date:
Mon Jan 13 17:45:38 2020 +0000
Revision:
3:ff2ce4f4c5cf
Parent:
2:3875bc678188
Child:
4:cfc02c02dd97
mit_lauflicht

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shogu 0:dfb1326f7f80 1 #include "mbed.h"
shogu 0:dfb1326f7f80 2 #define BUTTON1 p14 // M3: push joystick pin
shogu 0:dfb1326f7f80 3 // #define BUTTON1 A1 //NUCLEO: Taster A1
shogu 0:dfb1326f7f80 4
shogu 3:ff2ce4f4c5cf 5 int lauflicht(bool richtung, int time, int &anz);
shogu 1:899bf4117ea9 6 void nibbleLeds(int value);
shogu 2:3875bc678188 7 void printb(uint8_t x);
shogu 0:dfb1326f7f80 8
shogu 0:dfb1326f7f80 9 BusOut myleds(LED1, LED2, LED3, LED4);
shogu 0:dfb1326f7f80 10 DigitalIn button(BUTTON1);
shogu 0:dfb1326f7f80 11
shogu 0:dfb1326f7f80 12 const int INIT = 0x03;
shogu 0:dfb1326f7f80 13
shogu 0:dfb1326f7f80 14 int main() {
shogu 1:899bf4117ea9 15 int anzahl, anz;
shogu 1:899bf4117ea9 16 uint8_t value = INIT;
shogu 1:899bf4117ea9 17
shogu 3:ff2ce4f4c5cf 18 anzahl = lauflicht(true, 400, anz=0);
shogu 3:ff2ce4f4c5cf 19 printf("anzahl= %d\n", anzahl);
shogu 3:ff2ce4f4c5cf 20
shogu 1:899bf4117ea9 21 nibbleLeds(value);
shogu 2:3875bc678188 22 printb(value);
shogu 1:899bf4117ea9 23 wait(0.1);
shogu 0:dfb1326f7f80 24 }
shogu 1:899bf4117ea9 25
shogu 1:899bf4117ea9 26
shogu 3:ff2ce4f4c5cf 27 int lauflicht(bool richtung, int time, int &anz) {
shogu 3:ff2ce4f4c5cf 28 int i;
shogu 3:ff2ce4f4c5cf 29 uint8_t lauf = 0x01;
shogu 3:ff2ce4f4c5cf 30
shogu 3:ff2ce4f4c5cf 31 if(!richtung)
shogu 3:ff2ce4f4c5cf 32 lauf = 0x08;
shogu 3:ff2ce4f4c5cf 33 while(1) {
shogu 3:ff2ce4f4c5cf 34 nibbleLeds(lauf&0x0F);
shogu 3:ff2ce4f4c5cf 35 if(richtung) {
shogu 3:ff2ce4f4c5cf 36 lauf = lauf >>1;
shogu 3:ff2ce4f4c5cf 37 if(lauf < 8)
shogu 3:ff2ce4f4c5cf 38 lauf = 0x01;
shogu 3:ff2ce4f4c5cf 39 }
shogu 3:ff2ce4f4c5cf 40 else {
shogu 3:ff2ce4f4c5cf 41 lauf = lauf << 1;
shogu 3:ff2ce4f4c5cf 42 if(lauf == 0)
shogu 3:ff2ce4f4c5cf 43 lauf = 0x08;
shogu 3:ff2ce4f4c5cf 44 }
shogu 3:ff2ce4f4c5cf 45 if(button)
shogu 3:ff2ce4f4c5cf 46 break;
shogu 3:ff2ce4f4c5cf 47 wait_ms(time);
shogu 3:ff2ce4f4c5cf 48 anz++;
shogu 3:ff2ce4f4c5cf 49 }
shogu 3:ff2ce4f4c5cf 50 return anz;
shogu 3:ff2ce4f4c5cf 51 }
shogu 3:ff2ce4f4c5cf 52
shogu 3:ff2ce4f4c5cf 53
shogu 2:3875bc678188 54 void printb(uint8_t x) {
shogu 2:3875bc678188 55 for(int i=sizeof(x)<<3; i; i--)
shogu 2:3875bc678188 56 putchar('0'+((x<<(i-1))&1));
shogu 3:ff2ce4f4c5cf 57 printf("\n");
shogu 2:3875bc678188 58 }
shogu 2:3875bc678188 59
shogu 1:899bf4117ea9 60 void nibbleLeds(int value) {
shogu 1:899bf4117ea9 61 myleds = value%16;
shogu 3:ff2ce4f4c5cf 62 }
shogu 3:ff2ce4f4c5cf 63