Dimmer

From ThorstensHome
Revision as of 22:52, 21 April 2013 by WikiSysop (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Für das Elektronik Buch möchte ich unter Linux einen Dimmer bauen. Ich möchte eine LED so schnell pulsen, dass ich ihre Leuchtkraft steuern kann:

#define TXD 0x01
#define RXD 0x02
#define RTS 0x04
#define CTS 0x08
#define DTR 0x10
#define DSR 0x20
#define DCD 0x40
#define RI  0x80

#include <stdio.h>
#include <ftdi.h>

int main() 
{
    int result=0;
    struct ftdi_context context1;
    if (ftdi_init(&context1) >= 0) 
    {
        if (ftdi_usb_open(&context1, 0x0403, 0x6001) >= 0) // ft232r
        {
            int i;
            unsigned char on = 255-DTR;
	    unsigned char off = 255; 
            for (i = 0; i < 1000; i++) 
            {
                ftdi_write_data(&context1, &on, 1);
	        ftdi_write_data(&context1, &off, 1);
            }

            if (ftdi_usb_close(&context1) < 0) result = EXIT_FAILURE;
        }
        else result = EXIT_FAILURE;
    }
    else result = EXIT_FAILURE;
    if (result) fprintf(stderr, "Fehler: %s\n", ftdi_get_error_string(&context1));
    return result;
}