Alec Arce
/
PROJECT
Yo here you go kemal
main.cpp@0:0dd4a69da379, 2020-12-05 (annotated)
- Committer:
- xalec
- Date:
- Sat Dec 05 06:19:45 2020 +0000
- Revision:
- 0:0dd4a69da379
CS 435
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xalec | 0:0dd4a69da379 | 1 | #include <iostream> |
xalec | 0:0dd4a69da379 | 2 | |
xalec | 0:0dd4a69da379 | 3 | #include "mbed.h" |
xalec | 0:0dd4a69da379 | 4 | #include "Map.hpp" |
xalec | 0:0dd4a69da379 | 5 | #include "TCS3200.h" |
xalec | 0:0dd4a69da379 | 6 | |
xalec | 0:0dd4a69da379 | 7 | DigitalOut red(PA_9); |
xalec | 0:0dd4a69da379 | 8 | DigitalOut green(PC_7); |
xalec | 0:0dd4a69da379 | 9 | DigitalOut blue(PB_6); |
xalec | 0:0dd4a69da379 | 10 | |
xalec | 0:0dd4a69da379 | 11 | Serial pc(USBTX, USBRX); |
xalec | 0:0dd4a69da379 | 12 | |
xalec | 0:0dd4a69da379 | 13 | /** |
xalec | 0:0dd4a69da379 | 14 | Nucleo - TCS3200 interfacing pins |
xalec | 0:0dd4a69da379 | 15 | s0 (PA_8); // pin D7 |
xalec | 0:0dd4a69da379 | 16 | s1 (PB_10); // pin D6 |
xalec | 0:0dd4a69da379 | 17 | s2 (PB_4); // pin D5 |
xalec | 0:0dd4a69da379 | 18 | s3 (PB_5); // pin D4 |
xalec | 0:0dd4a69da379 | 19 | */ |
xalec | 0:0dd4a69da379 | 20 | |
xalec | 0:0dd4a69da379 | 21 | int main() { |
xalec | 0:0dd4a69da379 | 22 | |
xalec | 0:0dd4a69da379 | 23 | |
xalec | 0:0dd4a69da379 | 24 | int red_pw, green_pw, blue_pw; |
xalec | 0:0dd4a69da379 | 25 | int input; |
xalec | 0:0dd4a69da379 | 26 | int counter = 0; |
xalec | 0:0dd4a69da379 | 27 | |
xalec | 0:0dd4a69da379 | 28 | // Pulse width calibration values |
xalec | 0:0dd4a69da379 | 29 | int red_min = 31; |
xalec | 0:0dd4a69da379 | 30 | int red_max = 301; |
xalec | 0:0dd4a69da379 | 31 | int green_min = 37; |
xalec | 0:0dd4a69da379 | 32 | int green_max = 389; |
xalec | 0:0dd4a69da379 | 33 | int blue_min = 29; |
xalec | 0:0dd4a69da379 | 34 | int blue_max = 310; |
xalec | 0:0dd4a69da379 | 35 | int R, G, B; |
xalec | 0:0dd4a69da379 | 36 | |
xalec | 0:0dd4a69da379 | 37 | TCS3200 pw(PA_8, PB_10, PB_4, PB_5, PA_5); |
xalec | 0:0dd4a69da379 | 38 | |
xalec | 0:0dd4a69da379 | 39 | Map r_map(red_min, red_max, 255, 0); |
xalec | 0:0dd4a69da379 | 40 | Map g_map(green_min, green_max, 255, 0); |
xalec | 0:0dd4a69da379 | 41 | Map b_map(blue_min, blue_max, 255, 0); |
xalec | 0:0dd4a69da379 | 42 | |
xalec | 0:0dd4a69da379 | 43 | |
xalec | 0:0dd4a69da379 | 44 | pw.SetMode(TCS3200::SCALE_100); |
xalec | 0:0dd4a69da379 | 45 | |
xalec | 0:0dd4a69da379 | 46 | pc.printf("Please type a value:"); |
xalec | 0:0dd4a69da379 | 47 | pc.scanf("%i", &input); // & to pass a pointer to input |
xalec | 0:0dd4a69da379 | 48 | pc.printf("\nThe input value is: %i\n", input); |
xalec | 0:0dd4a69da379 | 49 | pc.printf("Reading in 3..."); |
xalec | 0:0dd4a69da379 | 50 | wait(1.5); |
xalec | 0:0dd4a69da379 | 51 | pc.printf("2..."); |
xalec | 0:0dd4a69da379 | 52 | wait(1.5); |
xalec | 0:0dd4a69da379 | 53 | pc.printf("1\n"); |
xalec | 0:0dd4a69da379 | 54 | while(counter < input){ |
xalec | 0:0dd4a69da379 | 55 | |
xalec | 0:0dd4a69da379 | 56 | |
xalec | 0:0dd4a69da379 | 57 | red_pw = pw.ReadRed(); |
xalec | 0:0dd4a69da379 | 58 | green_pw = pw.ReadGreen(); |
xalec | 0:0dd4a69da379 | 59 | blue_pw = pw.ReadBlue(); |
xalec | 0:0dd4a69da379 | 60 | |
xalec | 0:0dd4a69da379 | 61 | //printf("Red: %d Green: %d Blue: %d \n\r", red_pw, green_pw, blue_pw); |
xalec | 0:0dd4a69da379 | 62 | |
xalec | 0:0dd4a69da379 | 63 | |
xalec | 0:0dd4a69da379 | 64 | R = r_map.Calculate(red_pw); |
xalec | 0:0dd4a69da379 | 65 | G = g_map.Calculate(green_pw); |
xalec | 0:0dd4a69da379 | 66 | B = b_map.Calculate(blue_pw); |
xalec | 0:0dd4a69da379 | 67 | |
xalec | 0:0dd4a69da379 | 68 | if(R < 0) |
xalec | 0:0dd4a69da379 | 69 | R = 0; |
xalec | 0:0dd4a69da379 | 70 | else if(R > 255) |
xalec | 0:0dd4a69da379 | 71 | R = 255; |
xalec | 0:0dd4a69da379 | 72 | |
xalec | 0:0dd4a69da379 | 73 | |
xalec | 0:0dd4a69da379 | 74 | if(G < 0) |
xalec | 0:0dd4a69da379 | 75 | G = 0; |
xalec | 0:0dd4a69da379 | 76 | else if(G > 255) |
xalec | 0:0dd4a69da379 | 77 | G = 255; |
xalec | 0:0dd4a69da379 | 78 | |
xalec | 0:0dd4a69da379 | 79 | |
xalec | 0:0dd4a69da379 | 80 | if(B < 0) |
xalec | 0:0dd4a69da379 | 81 | B = 0; |
xalec | 0:0dd4a69da379 | 82 | else if(B > 255) |
xalec | 0:0dd4a69da379 | 83 | B = 255; |
xalec | 0:0dd4a69da379 | 84 | |
xalec | 0:0dd4a69da379 | 85 | printf("Red: %i Green: %i Blue: %i \n", R, G, B); |
xalec | 0:0dd4a69da379 | 86 | |
xalec | 0:0dd4a69da379 | 87 | wait(.5); |
xalec | 0:0dd4a69da379 | 88 | |
xalec | 0:0dd4a69da379 | 89 | counter++; |
xalec | 0:0dd4a69da379 | 90 | } |
xalec | 0:0dd4a69da379 | 91 | |
xalec | 0:0dd4a69da379 | 92 | } |