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@14:8ceaa97cc85c, 2020-12-01 (annotated)
- Committer:
- bky
- Date:
- Tue Dec 01 09:08:37 2020 +0000
- Revision:
- 14:8ceaa97cc85c
- Parent:
- 13:a1a9f2282f15
- Child:
- 16:def6abcb4294
created header file for 7 segment display driver
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bky | 10:8d86e59fb408 | 1 | # include "mbed.h" |
| bky | 10:8d86e59fb408 | 2 | # include "Timer.h" |
| bky | 9:b7e8d0372f53 | 3 | |
| bky | 10:8d86e59fb408 | 4 | # include <time.h> |
| bky | 10:8d86e59fb408 | 5 | # define NUM_HOLES 32 |
| bky | 10:8d86e59fb408 | 6 | # define CIRCUMFRENCE_CM 48.6946861 |
| bky | 9:b7e8d0372f53 | 7 | |
| bky | 9:b7e8d0372f53 | 8 | # define LIGHT_SENSOR_PIN p15 |
| bky | 14:8ceaa97cc85c | 9 | # define FLASH_THRESHOLD 0.02 |
| bky | 14:8ceaa97cc85c | 10 | # define PERIOD_MS 500 |
| bky | 9:b7e8d0372f53 | 11 | |
| bky | 9:b7e8d0372f53 | 12 | |
| bky | 9:b7e8d0372f53 | 13 | AnalogIn lightSensorVoltage(LIGHT_SENSOR_PIN); |
| bky | 9:b7e8d0372f53 | 14 | Serial pc(USBTX, USBRX); |
| bky | 0:d724bf9c4031 | 15 | |
| bky | 9:b7e8d0372f53 | 16 | void sendFloat(float value) { |
| bky | 9:b7e8d0372f53 | 17 | for (int i=0; i<4; i++) |
| bky | 9:b7e8d0372f53 | 18 | pc.putc(*(((char*) &value)+i)); |
| bky | 9:b7e8d0372f53 | 19 | } |
| bky | 9:b7e8d0372f53 | 20 | |
| bky | 14:8ceaa97cc85c | 21 | void displayThread() { |
| bky | 10:8d86e59fb408 | 22 | |
| bky | 14:8ceaa97cc85c | 23 | } |
| bky | 14:8ceaa97cc85c | 24 | |
| bky | 14:8ceaa97cc85c | 25 | int main() { |
| bky | 14:8ceaa97cc85c | 26 | while(true) { |
| bky | 14:8ceaa97cc85c | 27 | float minVoltage = 1.1; // voltage will never go above 1.0 |
| bky | 14:8ceaa97cc85c | 28 | int voltagePeaks = 0; |
| bky | 13:a1a9f2282f15 | 29 | |
| bky | 14:8ceaa97cc85c | 30 | Timer t; |
| bky | 14:8ceaa97cc85c | 31 | t.start(); |
| bky | 13:a1a9f2282f15 | 32 | |
| bky | 14:8ceaa97cc85c | 33 | while(t.read_ms() < PERIOD_MS) { |
| bky | 14:8ceaa97cc85c | 34 | float currVoltage = lightSensorVoltage.read(); |
| bky | 14:8ceaa97cc85c | 35 | if(currVoltage < minVoltage) { |
| bky | 14:8ceaa97cc85c | 36 | minVoltage = currVoltage; |
| bky | 14:8ceaa97cc85c | 37 | } else if (currVoltage - minVoltage > FLASH_THRESHOLD) { |
| bky | 14:8ceaa97cc85c | 38 | voltagePeaks++; |
| bky | 14:8ceaa97cc85c | 39 | minVoltage = 1.1; |
| bky | 14:8ceaa97cc85c | 40 | } |
| bky | 14:8ceaa97cc85c | 41 | wait(0.01); |
| bky | 10:8d86e59fb408 | 42 | } |
| bky | 13:a1a9f2282f15 | 43 | |
| bky | 14:8ceaa97cc85c | 44 | t.stop(); |
| bky | 13:a1a9f2282f15 | 45 | |
| bky | 14:8ceaa97cc85c | 46 | // calculate velocity |
| bky | 14:8ceaa97cc85c | 47 | float velocity = (voltagePeaks * CIRCUMFRENCE_CM * 1000) / (NUM_HOLES * PERIOD_MS); |
| bky | 13:a1a9f2282f15 | 48 | |
| bky | 14:8ceaa97cc85c | 49 | //send |
| bky | 14:8ceaa97cc85c | 50 | sendFloat(velocity); |
| bky | 7:12eed49f95fc | 51 | } |
| bky | 14:8ceaa97cc85c | 52 | return 0; |
| bky | 10:8d86e59fb408 | 53 | } |
