
Test program for: Nucleo_F334R8 and 4relay Shield from Seeed Studio http://www.seeedstudio.com/wiki/Relay_Shield_V2.0
Revision 1:f3da8a85e312, committed 2015-03-22
- Comitter:
- emcu
- Date:
- Sun Mar 22 00:46:34 2015 +0000
- Parent:
- 0:c9d8fcdda4d0
- Commit message:
- Test program for:; Nucleo_F334R8 that drive the 4relay Shield from Seeed Studio
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r c9d8fcdda4d0 -r f3da8a85e312 main.cpp --- a/main.cpp Fri Feb 21 12:57:03 2014 +0000 +++ b/main.cpp Sun Mar 22 00:46:34 2015 +0000 @@ -1,14 +1,101 @@ #include "mbed.h" + +/* + By www.emcu.it + + Test the: 4 relay shield from seeed studio + http://www.seeedstudio.com/wiki/Relay_Shield_V2.0 + + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * +*/ + + +// NOTE: The Serial pc & Serial device are not used in this example +Serial pc(SERIAL_TX, SERIAL_RX); // This is USART2 tx, rx - It is used for debug (Usb Virtual Com) +Serial device(PB_6, PA_10); // This is USART1 tx, rx +//------------------------------------ +// UART configuration: +// 9600 bauds, 8-bit data, no parity +//------------------------------------ + DigitalIn mybutton(USER_BUTTON); -DigitalOut myled(LED1); +DigitalOut LED(PA_5); +DigitalOut RL1(PA_8); // Relè n.1 +DigitalOut RL2(PB_10); // Relè n.2 +DigitalOut RL3(PB_4); // Relè n.3 +DigitalOut RL4(PB_5); // Relè n.4 + +#define NonPremuto 1 +#define Premuto 0 + +int Tasto = NonPremuto; + +void OnRELE_forTime(int Rele, float Tempo); + -int main() { - while(1) { - if (mybutton == 0) { // Button is pressed - myled = !myled; // Toggle the LED state - wait(0.2); // 200 ms +int main() +{ + while(1) + { + // Tasto = mybutton; + if (mybutton == Premuto) + { // Button is pressed + LED = !LED; // Toggle the LED state + OnRELE_forTime(1, 2); // ON RL1 for 2sec + OnRELE_forTime(2, 2); // ON RL2 for 2sec + OnRELE_forTime(3, 2); // ON RL3 for 2sec + OnRELE_forTime(4, 2); // ON RL4 for 2sec } } } - \ No newline at end of file + + +void OnRELE_forTime(int Rele, float Tempo) +{ + if (Rele == 1) + { + RL1 = 1; + wait(Tempo); + RL1 = 0; + } + + if (Rele == 2) + { + RL2 = 1; + wait(Tempo); + RL2 = 0; + } + + if (Rele == 3) + { + RL3 = 1; + wait(Tempo); + RL3 = 0; + } + + if (Rele == 4) + { + RL4 = 1; + wait(Tempo); + RL4 = 0; + } +}
diff -r c9d8fcdda4d0 -r f3da8a85e312 mbed.bld --- a/mbed.bld Fri Feb 21 12:57:03 2014 +0000 +++ b/mbed.bld Sun Mar 22 00:46:34 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ed8466a608b4 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file