Be careful - it can harm your computer, so shut down PC first.
C
Program demonstrates basic parapin library usage. Get parapin library from http://parapin.sourceforge.net/ and install it.Create led.c file:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include "parapin.h" int main(int argc, char *argv[]) { int pin = 5; if (pin_init_user(LPT1) < 0) exit(0); pin_output_mode(LP_DATA_PINS | LP_SWITCHABLE_PINS); set_pin(LP_PIN[pin]); sleep(5); clear_pin(LP_PIN[pin]); return 0; }Then compile above program with command
gcc led.c -O -lparapin -o ledand run
sudo ./ledThe program will flash your LED diode for 5 seconds.
Python
The same can be done with Python and it seems to be much easier. Take a look at led.pyimport parallel import time p=parallel.Parallel() p.setData(0x8) time.sleep(5) p.setData(0x0)
Remarks
If you want to run led.py you need to remove lp module from kernel. C program doesn't have such limitations.Note, that both programs need to be run with root privilages.
Brak komentarzy:
Prześlij komentarz