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.
ColourSensor_H.h@0:23508e7103a4, 2019-03-18 (annotated)
- Committer:
- quickeman
- Date:
- Mon Mar 18 11:21:43 2019 +0000
- Revision:
- 0:23508e7103a4
Version 2 of OOP Colour Sensor program.; ; Altered so solenoid is ON by default and only turns OFF when dropping disk.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| quickeman | 0:23508e7103a4 | 1 | // ColourSensor_H.h | 
| quickeman | 0:23508e7103a4 | 2 | |
| quickeman | 0:23508e7103a4 | 3 | #ifndef ColourSensor_H | 
| quickeman | 0:23508e7103a4 | 4 | #define ColourSensor_H | 
| quickeman | 0:23508e7103a4 | 5 | |
| quickeman | 0:23508e7103a4 | 6 | #include "mbed.h" | 
| quickeman | 0:23508e7103a4 | 7 | |
| quickeman | 0:23508e7103a4 | 8 | // ColourSensor is used to detect the coloured disks and control the Solenoid | 
| quickeman | 0:23508e7103a4 | 9 | /* Attributes: | 
| quickeman | 0:23508e7103a4 | 10 | - Pinouts of sensor inputs and solenoid output | 
| quickeman | 0:23508e7103a4 | 11 | |
| quickeman | 0:23508e7103a4 | 12 | Methods: | 
| quickeman | 0:23508e7103a4 | 13 | - solenoidSet | 
| quickeman | 0:23508e7103a4 | 14 | - readColSenIf | 
| quickeman | 0:23508e7103a4 | 15 | - readColSenWhich | 
| quickeman | 0:23508e7103a4 | 16 | - colourCheck | 
| quickeman | 0:23508e7103a4 | 17 | - makeColourActive | 
| quickeman | 0:23508e7103a4 | 18 | */ | 
| quickeman | 0:23508e7103a4 | 19 | |
| quickeman | 0:23508e7103a4 | 20 | class ColourSensor { | 
| quickeman | 0:23508e7103a4 | 21 | public: | 
| quickeman | 0:23508e7103a4 | 22 | void solenoidSet(bool state); // Setting solenoid state | 
| quickeman | 0:23508e7103a4 | 23 | void solenoidOn(); // Interrupt to turn ON solenoid | 
| quickeman | 0:23508e7103a4 | 24 | void readIf(); // Read 'IF' sensor | 
| quickeman | 0:23508e7103a4 | 25 | void readWhich(); // Read 'WHICH' sensor | 
| quickeman | 0:23508e7103a4 | 26 | void process(); // Colour processing | 
| quickeman | 0:23508e7103a4 | 27 | void initialConditions(); // Sets initial conditions | 
| quickeman | 0:23508e7103a4 | 28 | |
| quickeman | 0:23508e7103a4 | 29 | DigitalIn inIf; | 
| quickeman | 0:23508e7103a4 | 30 | DigitalIn inWhich; | 
| quickeman | 0:23508e7103a4 | 31 | DigitalOut solenoid; | 
| quickeman | 0:23508e7103a4 | 32 | |
| quickeman | 0:23508e7103a4 | 33 | int firstLoop; | 
| quickeman | 0:23508e7103a4 | 34 | bool toggleA; | 
| quickeman | 0:23508e7103a4 | 35 | bool toggleB; | 
| quickeman | 0:23508e7103a4 | 36 | bool toggleConst; // Can be used to toggle colour processing | 
| quickeman | 0:23508e7103a4 | 37 | |
| quickeman | 0:23508e7103a4 | 38 | bool flagColour; | 
| quickeman | 0:23508e7103a4 | 39 | |
| quickeman | 0:23508e7103a4 | 40 | ColourSensor(PinName pin1, PinName pin2, PinName pin3); | 
| quickeman | 0:23508e7103a4 | 41 | |
| quickeman | 0:23508e7103a4 | 42 | void makeColourActive(); | 
| quickeman | 0:23508e7103a4 | 43 | |
| quickeman | 0:23508e7103a4 | 44 | |
| quickeman | 0:23508e7103a4 | 45 | private: | 
| quickeman | 0:23508e7103a4 | 46 | bool detectedIf; // Colour detected? Yes/No -> 1/0 | 
| quickeman | 0:23508e7103a4 | 47 | bool detectedIfOld; // Comparison bool | 
| quickeman | 0:23508e7103a4 | 48 | bool newDetection; // Colour newly detected? (i.e. is now but wasn't before?) Yes/No -> 1/0 | 
| quickeman | 0:23508e7103a4 | 49 | bool detectedWhich; // Colour detected: Red/Blue -> 1/0 | 
| quickeman | 0:23508e7103a4 | 50 | bool diskHave; // Have disk? Yes/No -> 1/0 | 
| quickeman | 0:23508e7103a4 | 51 | bool diskColour; // Colour of disk: Red/Blue -> 1/0 | 
| quickeman | 0:23508e7103a4 | 52 | |
| quickeman | 0:23508e7103a4 | 53 | bool solenoidState; // State of solenoid: On/Off -> 1/0 | 
| quickeman | 0:23508e7103a4 | 54 | |
| quickeman | 0:23508e7103a4 | 55 | }; | 
| quickeman | 0:23508e7103a4 | 56 | |
| quickeman | 0:23508e7103a4 | 57 | #endif |