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.
test.cpp@4:179695a6d7fd, 2020-01-13 (annotated)
- Committer:
- robertbuc
- Date:
- Mon Jan 13 17:39:15 2020 +0000
- Revision:
- 4:179695a6d7fd
- Parent:
- 3:380bc168e247
- Child:
- 5:d0e564605224
nibble,printb und lauflicht
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| robertbuc | 0:136627249b57 | 1 | /* |
| robertbuc | 0:136627249b57 | 2 | weitere viele Beispiele in meinem WIKI |
| robertbuc | 1:06d6570e52bc | 3 | |
| robertbuc | 1:06d6570e52bc | 4 | */ |
| robertbuc | 2:db4c700f1898 | 5 | |
| robertbuc | 1:06d6570e52bc | 6 | #include "mbed.h" |
| robertbuc | 1:06d6570e52bc | 7 | //#define BUTTON1 p14 |
| robertbuc | 1:06d6570e52bc | 8 | //#define BUTTON1 A1 |
| robertbuc | 0:136627249b57 | 9 | |
| robertbuc | 0:136627249b57 | 10 | |
| robertbuc | 1:06d6570e52bc | 11 | void nibbleLeds(int value); |
| robertbuc | 2:db4c700f1898 | 12 | void printb(uint8_t x); |
| robertbuc | 4:179695a6d7fd | 13 | int lauflicht(bool richtung, int time, int &anz); |
| robertbuc | 0:136627249b57 | 14 | |
| robertbuc | 1:06d6570e52bc | 15 | BusOut myleds(LED1,LED2,LED3,LED4); |
| robertbuc | 0:136627249b57 | 16 | DigitalIn button(BUTTON1); |
| robertbuc | 0:136627249b57 | 17 | |
| robertbuc | 0:136627249b57 | 18 | const int INIT=0x03; |
| robertbuc | 0:136627249b57 | 19 | |
| robertbuc | 0:136627249b57 | 20 | int main() |
| robertbuc | 0:136627249b57 | 21 | { |
| robertbuc | 1:06d6570e52bc | 22 | int anzahl,anz; |
| robertbuc | 1:06d6570e52bc | 23 | uint8_t value=INIT; |
| robertbuc | 4:179695a6d7fd | 24 | |
| robertbuc | 4:179695a6d7fd | 25 | anzahl=lauflicht(true,400,anz=0); |
| robertbuc | 4:179695a6d7fd | 26 | printf("anzahl= %d\n",anzahl); |
| robertbuc | 1:06d6570e52bc | 27 | |
| robertbuc | 1:06d6570e52bc | 28 | nibbleLeds(value); |
| robertbuc | 2:db4c700f1898 | 29 | printb(value); |
| robertbuc | 1:06d6570e52bc | 30 | wait(0.1); |
| robertbuc | 1:06d6570e52bc | 31 | } |
| robertbuc | 1:06d6570e52bc | 32 | |
| robertbuc | 4:179695a6d7fd | 33 | int lauflicht(bool richtung, int time, int &anz) |
| robertbuc | 4:179695a6d7fd | 34 | { |
| robertbuc | 4:179695a6d7fd | 35 | int i; |
| robertbuc | 4:179695a6d7fd | 36 | uint8_t lauf=0x01; |
| robertbuc | 4:179695a6d7fd | 37 | |
| robertbuc | 4:179695a6d7fd | 38 | if(!richtung) |
| robertbuc | 4:179695a6d7fd | 39 | { |
| robertbuc | 4:179695a6d7fd | 40 | lauf=0x08; |
| robertbuc | 4:179695a6d7fd | 41 | } |
| robertbuc | 4:179695a6d7fd | 42 | while(1) |
| robertbuc | 4:179695a6d7fd | 43 | { |
| robertbuc | 4:179695a6d7fd | 44 | nibbleLeds(lauf&0x0F); |
| robertbuc | 4:179695a6d7fd | 45 | if(richtung) |
| robertbuc | 4:179695a6d7fd | 46 | { |
| robertbuc | 4:179695a6d7fd | 47 | lauf=lauf<<1; |
| robertbuc | 4:179695a6d7fd | 48 | if(lauf>8) |
| robertbuc | 4:179695a6d7fd | 49 | lauf=0x01; |
| robertbuc | 4:179695a6d7fd | 50 | } |
| robertbuc | 4:179695a6d7fd | 51 | else |
| robertbuc | 4:179695a6d7fd | 52 | { |
| robertbuc | 4:179695a6d7fd | 53 | lauf=lauf>>1; |
| robertbuc | 4:179695a6d7fd | 54 | if(lauf==0) |
| robertbuc | 4:179695a6d7fd | 55 | { |
| robertbuc | 4:179695a6d7fd | 56 | lauf==0x08; |
| robertbuc | 4:179695a6d7fd | 57 | } |
| robertbuc | 4:179695a6d7fd | 58 | } |
| robertbuc | 4:179695a6d7fd | 59 | if(button) |
| robertbuc | 4:179695a6d7fd | 60 | break; |
| robertbuc | 4:179695a6d7fd | 61 | wait_ms(time); |
| robertbuc | 4:179695a6d7fd | 62 | anz++; |
| robertbuc | 4:179695a6d7fd | 63 | } |
| robertbuc | 4:179695a6d7fd | 64 | return anz; |
| robertbuc | 4:179695a6d7fd | 65 | } |
| robertbuc | 4:179695a6d7fd | 66 | |
| robertbuc | 4:179695a6d7fd | 67 | |
| robertbuc | 4:179695a6d7fd | 68 | |
| robertbuc | 2:db4c700f1898 | 69 | void printb(uint8_t x) |
| robertbuc | 1:06d6570e52bc | 70 | { |
| robertbuc | 2:db4c700f1898 | 71 | for(int i=sizeof(x)<<3;i;i--) |
| robertbuc | 2:db4c700f1898 | 72 | putchar('0'+((x>>(i-1))&1)); |
| robertbuc | 2:db4c700f1898 | 73 | printf("\n"); |
| robertbuc | 2:db4c700f1898 | 74 | } |
| robertbuc | 3:380bc168e247 | 75 | |
| robertbuc | 3:380bc168e247 | 76 | void nibbleLeds(int value) |
| robertbuc | 3:380bc168e247 | 77 | { |
| robertbuc | 3:380bc168e247 | 78 | myleds=value%16; |
| robertbuc | 3:380bc168e247 | 79 | } |