Example program for Motor Shield V2 by SeeedStudio. The shields uses D4-D7 to control 4 relays.
Dependencies: mbed
main.cpp@2:9172df351721, 2014-07-25 (annotated)
- Committer:
- screamer
- Date:
- Fri Jul 25 12:27:35 2014 +0000
- Revision:
- 2:9172df351721
- Parent:
- 0:f78a8d21569d
Add Apache2 license compatible header
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 2:9172df351721 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
screamer | 2:9172df351721 | 2 | * |
screamer | 2:9172df351721 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
screamer | 2:9172df351721 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
screamer | 2:9172df351721 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
screamer | 2:9172df351721 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
screamer | 2:9172df351721 | 7 | * Software is furnished to do so, subject to the following conditions: |
screamer | 2:9172df351721 | 8 | * |
screamer | 2:9172df351721 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
screamer | 2:9172df351721 | 10 | * substantial portions of the Software. |
screamer | 2:9172df351721 | 11 | * |
screamer | 2:9172df351721 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
screamer | 2:9172df351721 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
screamer | 2:9172df351721 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
screamer | 2:9172df351721 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
screamer | 2:9172df351721 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
screamer | 2:9172df351721 | 17 | */ |
screamer | 2:9172df351721 | 18 | |
screamer | 0:f78a8d21569d | 19 | #include "mbed.h" |
screamer | 0:f78a8d21569d | 20 | |
screamer | 0:f78a8d21569d | 21 | DigitalOut relay1(D7); // Relay 1 |
screamer | 0:f78a8d21569d | 22 | DigitalOut relay2(D6); // Relay 2 |
screamer | 0:f78a8d21569d | 23 | DigitalOut relay3(D5); // Relay 3 |
screamer | 0:f78a8d21569d | 24 | DigitalOut relay4(D4); // Relay 4 |
screamer | 0:f78a8d21569d | 25 | |
screamer | 0:f78a8d21569d | 26 | |
screamer | 0:f78a8d21569d | 27 | int main() { |
screamer | 0:f78a8d21569d | 28 | float tm = 0.2; |
screamer | 0:f78a8d21569d | 29 | int i=0; |
screamer | 0:f78a8d21569d | 30 | |
screamer | 0:f78a8d21569d | 31 | while(1) { |
screamer | 0:f78a8d21569d | 32 | for (i=0; i<16; i++) { |
screamer | 0:f78a8d21569d | 33 | relay1 = i & 1; |
screamer | 0:f78a8d21569d | 34 | relay2 = i & 2; |
screamer | 0:f78a8d21569d | 35 | relay3 = i & 4; |
screamer | 0:f78a8d21569d | 36 | relay4 = i & 8; |
screamer | 0:f78a8d21569d | 37 | wait(tm); |
screamer | 0:f78a8d21569d | 38 | } |
screamer | 0:f78a8d21569d | 39 | tm = tm / 1.2; |
screamer | 0:f78a8d21569d | 40 | if (tm < 0.005) break; |
screamer | 0:f78a8d21569d | 41 | } |
screamer | 0:f78a8d21569d | 42 | } |