Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| workshop:arduino [2009-06-23 21:23] – trapicki | workshop:arduino [2025-11-09 09:25] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| - | * [[http:// | + | * [[http:// |
| * [[http:// | * [[http:// | ||
| + | |||
| ==== Nützliche Scripts ==== | ==== Nützliche Scripts ==== | ||
| Line 46: | Line 47: | ||
| Ein kleines Programm, um einen Arduino zu reseten. Funktionsweise: | Ein kleines Programm, um einen Arduino zu reseten. Funktionsweise: | ||
| < | < | ||
| + | #include < | ||
| #include < | #include < | ||
| #include < | #include < | ||
| Line 51: | Line 53: | ||
| #include < | #include < | ||
| #include < | #include < | ||
| + | #include < | ||
| #define STATE_OFF 0 | #define STATE_OFF 0 | ||
| Line 64: | Line 67: | ||
| int | int | ||
| - | main(void) | + | main(int argc, char* argv[]) |
| { | { | ||
| - | | + | char* device = argc < 2 ? "/ |
| - | int fd; | + | int fd = open(device, |
| - | const struct timespec sleeptime = {0, 100000000}; // 100ms | + | |
| - | + | ||
| - | | + | |
| if (fd == 0) { | if (fd == 0) { | ||
| - | | + | |
| - | return | + | return |
| } | } | ||
| | | ||
| - | printf (" | ||
| setDTRState(fd, | setDTRState(fd, | ||
| - | | + | |
| + | select(0, NULL, NULL, NULL, & | ||
| setDTRState(fd, | setDTRState(fd, | ||
| - | | + | sleeptime.tv_sec = 0; |
| + | sleeptime.tv_usec = 100000; | ||
| + | select(0, NULL, NULL, NULL, & | ||
| setDTRState(fd, | setDTRState(fd, | ||
| close(fd); | close(fd); | ||
| + | |||
| + | return EXIT_SUCCESS; | ||
| } | } | ||
| </ | </ | ||
| Line 92: | Line 96: | ||
| < | < | ||
| + | === Besipiel: Lauflicht === | ||
| + | |||
| + | Je eine LED auf Pin 2 bis 7 schalten. | ||
| + | **Achtung: Alle Anoden gemeinsam auf +5V legen!** | ||
| + | |||
| + | Die Anoden der LEDs werden auf +5V gelegt, zum Einschalten der LED muss der entsprechende PIN deshalb auf LOW gesetzt werden. | ||
| + | |||
| + | < | ||
| + | #define LEDS_OFF 0xFC | ||
| + | #define LEDS_ON 0x00 | ||
| + | #define LEDS_INIT 0xF8 | ||
| + | #define INTERVALL 50 | ||
| + | |||
| + | byte counter; | ||
| + | byte direction; | ||
| + | |||
| + | void setup(){ | ||
| + | pinMode(13, OUTPUT); | ||
| + | digitalWrite(13, | ||
| + | |||
| + | counter = 0; | ||
| + | direction = 1; | ||
| + | |||
| + | DDRD = 0xFC; | ||
| + | PORTD = LEDS_INIT; | ||
| + | } | ||
| + | |||
| + | byte led_table(byte led){ | ||
| + | switch(led){ | ||
| + | case 0: return LEDS_INIT; | ||
| + | case 1: return 0xF4; | ||
| + | case 2: return 0xEC; | ||
| + | case 3: return 0xDC; | ||
| + | case 4: return 0xBC; | ||
| + | case 5: return 0x7C; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | byte get_next_state(){ | ||
| + | if(counter == 5) | ||
| + | direction = 0; | ||
| + | else if(counter == 0) | ||
| + | direction = 1; | ||
| + | |||
| + | return (direction)? | ||
| + | } | ||
| + | |||
| + | byte get_next_state_oneway(){ | ||
| + | counter++; | ||
| + | counter %= 6; | ||
| + | return led_table(counter); | ||
| + | } | ||
| + | |||
| + | void loop(){ | ||
| + | PORTD = get_next_state(); | ||
| + | //PORTD = get_next_state_oneway(); | ||
| + | delay(INTERVALL); | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
| ---- | ---- | ||
| {{tag> | {{tag> | ||