Ausgangslage
- Zugmagnet CII/A1464
- Elektromagnet 12 V- / 2,6 A 30 Watt
- Einschaltdauer 10 %
- Relais steuern die Zugmagnete
- 5 Bumber
- 4 Flips
Bedingungen
- die Einschaltdauer von 10 % einhalten
- z.B: innerhalb von 5 Sekunden darf das Relais nur maximal 0.5 Sekunden eingeschaltet sein
Aufbau
-
Seeeduino V4.2
- als Arduino UNO programmieren
- Input
- Output
Handlungsziele
Vorgehen | Hannok Handlungsnotwendige Kenntnisse |
---|---|
mehrere Relais steuern | Register / Array |
Einschaltdauer max 10% | Timer besser: Schieberegister |
schnelle Reaktion auf Ereignis | Interrupt, volatile |
Testbarkeit | Loggen, ASSERT |
Code Sample
/*
Grove LED Bar - Basic Control Example
This example will show you how to use the setBits() function of this library.
Set any combination of LEDs using 10 bits.
Least significant bit controls the first LED.
The setBits() function sets the current state, one bit for each LED.
First 10 bits from the right control the 10 LEDs.
eg. 0b00000jihgfedcba
a = LED 1, b = LED 2, c = LED 3, etc.
dec hex binary
0 = 0x0 = 0b000000000000000 = all LEDs off
5 = 0x05 = 0b000000000000101 = LEDs 1 and 3 on, all others off
341 = 0x155 = 0b000000101010101 = LEDs 1,3,5,7,9 on, 2,4,6,8,10 off
1023 = 0x3ff = 0b000001111111111 = all LEDs on
| |
10 1
The bits >10 are ignored, shown here as x: 0bxxxxx0000000000
*/
#include <Grove_LED_Bar.h>
Grove_LED_Bar bar(7, 6, 0); // Clock pin, Data pin, Orientation
void setup() {
// nothing to initialize
bar.begin();
}
void loop() {
// Turn on all LEDs
bar.setBits(0x3ff);
delay(1000);
// Turn off all LEDs
bar.setBits(0x0);
delay(1000);
// Turn on LED 1
// 0b000000000000001 can also be written as 0x1:
bar.setBits(0b000000000000001);
delay(1000);
// Turn on LEDs 1 and 3
// 0b000000000000101 can also be written as 0x5:
bar.setBits(0b000000000000101);
delay(1000);
// Turn on LEDs 1, 3, 5, 7, 9
bar.setBits(0x155);
delay(1000);
// Turn on LEDs 2, 4, 6, 8, 10
bar.setBits(0x2AA);
delay(1000);
// Turn on LEDs 1, 2, 3, 4, 5
// 0b000000000011111 == 0x1F
bar.setBits(0b000000000011111);
delay(1000);
// Turn on LEDs 6, 7, 8, 9, 10
// 0b000001111100000 == 0x3E0
bar.setBits(0b000001111100000);
delay(1000);
}
Grove LED Bar
Grove LED Bar is comprised of a 10 segment LED gauge bar and an MY9221 LED driver. It can be used as a indicator for remaining battery life, voltage, water level, music volume or other values that require a gradient display. There are 10 discrete LED bars in the LED bar graph: one red, one yellow, one light green, and the rest green.
For more information, please refer to the wiki: Grove_LED_Bar and LED_Bar
SKU: LED05031P
This software is written by Frankie Chu for seeed studio
and is licensed under The MIT License. Check License.txt for more information.
Contributing to this software is warmly welcomed. You can do this basically by
forking, committing modifications and then pulling requests (follow the links above
for operating guide). Adding change log and your contact into file header is encouraged.
Thanks for your contribution.
Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
Benefiting from local manufacture power and convenient global logistic system,
we integrate resources to serve new era of innovation. Seeed also works with
global distributors and partners to push open hardware movement.