Example project for the Rioux Chem control box
Rioux Chem Control Box
This is the example project for the Rioux Chem Control Box. I have posted some youtube videos to guide you through the hardware and software:
Rioux Chem Control Box - Hardware
http://www.youtube.com/watch?v=MoZ92GRYa4s
Rioux Chem Control Box - Software - Part I
http://www.youtube.com/watch?v=_MwaTLL4dyA==
Rioux Chem Control Box - Software - Part II
http://www.youtube.com/watch?v=j_P89izfgoQ
main.cpp@0:7798270c1f52, 2014-01-25 (annotated)
- Committer:
- emh203
- Date:
- Sat Jan 25 19:10:17 2014 +0000
- Revision:
- 0:7798270c1f52
- Child:
- 2:73a028278c5c
1st version to Demo! All interfaces tested and working
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emh203 | 0:7798270c1f52 | 1 | #include "mbed.h" |
| emh203 | 0:7798270c1f52 | 2 | #include "CHEM_BOX_INTERFACE.h" |
| emh203 | 0:7798270c1f52 | 3 | |
| emh203 | 0:7798270c1f52 | 4 | Timer ControlLoopTimer; |
| emh203 | 0:7798270c1f52 | 5 | float CurrentTemperature; |
| emh203 | 0:7798270c1f52 | 6 | |
| emh203 | 0:7798270c1f52 | 7 | |
| emh203 | 0:7798270c1f52 | 8 | int main() |
| emh203 | 0:7798270c1f52 | 9 | { |
| emh203 | 0:7798270c1f52 | 10 | int i; |
| emh203 | 0:7798270c1f52 | 11 | |
| emh203 | 0:7798270c1f52 | 12 | //This function always needs called before you do anythign wit the CHEM BOX. |
| emh203 | 0:7798270c1f52 | 13 | InitChemBox(); |
| emh203 | 0:7798270c1f52 | 14 | |
| emh203 | 0:7798270c1f52 | 15 | //Beep 6 times |
| emh203 | 0:7798270c1f52 | 16 | for(i=0;i<6;i++) |
| emh203 | 0:7798270c1f52 | 17 | { |
| emh203 | 0:7798270c1f52 | 18 | Buzz(.05); //Since the Buzz function immediately returns we should wait a bit before calling it again in the loop |
| emh203 | 0:7798270c1f52 | 19 | wait(.1); //I want a 50% duty cycle so I will wait twice as long as my previous Buzz() call |
| emh203 | 0:7798270c1f52 | 20 | } |
| emh203 | 0:7798270c1f52 | 21 | |
| emh203 | 0:7798270c1f52 | 22 | |
| emh203 | 0:7798270c1f52 | 23 | //Here is an example of how to draw on the screen! |
| emh203 | 0:7798270c1f52 | 24 | |
| emh203 | 0:7798270c1f52 | 25 | //This makes the backlight white. Each color can be between 0 and 3 (integers... 0,1,2,3) |
| emh203 | 0:7798270c1f52 | 26 | SmartSwitch_SetBackLightColor(3, 3, 3); |
| emh203 | 0:7798270c1f52 | 27 | |
| emh203 | 0:7798270c1f52 | 28 | //The display routines are fully buffered. When you call the draw routines, the write to the backbuffer, not the screen. |
| emh203 | 0:7798270c1f52 | 29 | //The flow is to clear the backbuffer, call all the drawing routines, then dump the backbuffer to the screen. |
| emh203 | 0:7798270c1f52 | 30 | |
| emh203 | 0:7798270c1f52 | 31 | //This clears the back buffer |
| emh203 | 0:7798270c1f52 | 32 | GFX_FullDisplayBufferClear(&BackBuffer); |
| emh203 | 0:7798270c1f52 | 33 | |
| emh203 | 0:7798270c1f52 | 34 | //Draw a box around the edge of the screen |
| emh203 | 0:7798270c1f52 | 35 | |
| emh203 | 0:7798270c1f52 | 36 | GFX_DrawLine(&BackBuffer, 0,0, PHYSICAL_DISPLAY_XRES - 1,0); |
| emh203 | 0:7798270c1f52 | 37 | GFX_DrawLine(&BackBuffer, PHYSICAL_DISPLAY_XRES - 1,0,PHYSICAL_DISPLAY_XRES - 1 ,PHYSICAL_DISPLAY_YRES - 1); |
| emh203 | 0:7798270c1f52 | 38 | GFX_DrawLine(&BackBuffer, PHYSICAL_DISPLAY_XRES - 1 ,PHYSICAL_DISPLAY_YRES - 1,0,PHYSICAL_DISPLAY_YRES - 1); |
| emh203 | 0:7798270c1f52 | 39 | GFX_DrawLine(&BackBuffer,0, PHYSICAL_DISPLAY_YRES - 1,0,0); |
| emh203 | 0:7798270c1f52 | 40 | |
| emh203 | 0:7798270c1f52 | 41 | //Draw a plain string using the 5x7 font. |
| emh203 | 0:7798270c1f52 | 42 | GFX_DrawString(&BackBuffer,"Rioux Box",6,2, &Font5x7); |
| emh203 | 0:7798270c1f52 | 43 | |
| emh203 | 0:7798270c1f52 | 44 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES - 1 ,12); |
| emh203 | 0:7798270c1f52 | 45 | |
| emh203 | 0:7798270c1f52 | 46 | //This shows how to do a printf. Using this allows you to put internal variables, etc on the screen. |
| emh203 | 0:7798270c1f52 | 47 | //Just lookup documentation on printf on the web to see examples of escape sequences in the control strings |
| emh203 | 0:7798270c1f52 | 48 | //In this example API_VERSION is a string so we use %s to display it |
| emh203 | 0:7798270c1f52 | 49 | GFX_printf(&BackBuffer,15,20, &Font3x5,"Ver: %s",API_VERSION); |
| emh203 | 0:7798270c1f52 | 50 | |
| emh203 | 0:7798270c1f52 | 51 | //Move the backbuffer to the actual display |
| emh203 | 0:7798270c1f52 | 52 | GFX_DumpRenderContextToPhysicalScreen(&BackBuffer); |
| emh203 | 0:7798270c1f52 | 53 | |
| emh203 | 0:7798270c1f52 | 54 | |
| emh203 | 0:7798270c1f52 | 55 | //Here is the main super loop |
| emh203 | 0:7798270c1f52 | 56 | |
| emh203 | 0:7798270c1f52 | 57 | //reset and start our control loop Timer |
| emh203 | 0:7798270c1f52 | 58 | ControlLoopTimer.reset(); |
| emh203 | 0:7798270c1f52 | 59 | ControlLoopTimer.start(); |
| emh203 | 0:7798270c1f52 | 60 | |
| emh203 | 0:7798270c1f52 | 61 | while(1) |
| emh203 | 0:7798270c1f52 | 62 | { |
| emh203 | 0:7798270c1f52 | 63 | //Call this often if you want the USB interface/Terminal |
| emh203 | 0:7798270c1f52 | 64 | ProcessTerminal(); |
| emh203 | 0:7798270c1f52 | 65 | |
| emh203 | 0:7798270c1f52 | 66 | /* |
| emh203 | 0:7798270c1f52 | 67 | |
| emh203 | 0:7798270c1f52 | 68 | //control loop example |
| emh203 | 0:7798270c1f52 | 69 | //We will do something ever 250mS. |
| emh203 | 0:7798270c1f52 | 70 | //Use a timer and an if statement we won't hold the microprocessor from do other things in the main super loop! |
| emh203 | 0:7798270c1f52 | 71 | if(ControlLoopTimer.read_ms >= 250) |
| emh203 | 0:7798270c1f52 | 72 | { |
| emh203 | 0:7798270c1f52 | 73 | ControlLoopTimer.reset(); |
| emh203 | 0:7798270c1f52 | 74 | |
| emh203 | 0:7798270c1f52 | 75 | //if 250mSec has elapsed then do our control loop |
| emh203 | 0:7798270c1f52 | 76 | |
| emh203 | 0:7798270c1f52 | 77 | CurrentTemperature = ReadThermocouple(0); |
| emh203 | 0:7798270c1f52 | 78 | |
| emh203 | 0:7798270c1f52 | 79 | if(CurrentTemperature < 15.5) |
| emh203 | 0:7798270c1f52 | 80 | { |
| emh203 | 0:7798270c1f52 | 81 | EnableHeater(0); |
| emh203 | 0:7798270c1f52 | 82 | } |
| emh203 | 0:7798270c1f52 | 83 | else |
| emh203 | 0:7798270c1f52 | 84 | { |
| emh203 | 0:7798270c1f52 | 85 | DisableHeater(0); |
| emh203 | 0:7798270c1f52 | 86 | } |
| emh203 | 0:7798270c1f52 | 87 | |
| emh203 | 0:7798270c1f52 | 88 | FlushDigitalIO(); //Remeber, the digital outs are queued up until this is called! |
| emh203 | 0:7798270c1f52 | 89 | } |
| emh203 | 0:7798270c1f52 | 90 | */ |
| emh203 | 0:7798270c1f52 | 91 | } |
| emh203 | 0:7798270c1f52 | 92 | |
| emh203 | 0:7798270c1f52 | 93 | } |
Eli Hughes

