1: instale
sudo apt-get install vim
2: Conecte
3: Abra terminal y cree un archivo
$ sudo vim blink.c
|
4: Pegar el siguiente código:
#include <wiringPi.h>
#include <stdio.h>
#define LedPin 0
int main(void) {
if(wiringPiSetup() == -1) { //when initialize wiringPi failed, print message to screen
printf("setup wiringPi failed !\n");
return -1;
}
pinMode(LedPin, OUTPUT);
while(1) {
digitalWrite(LedPin, LOW); //led on
printf("led on\n");
delay(1000); // wait 1 sec
digitalWrite(LedPin, HIGH); //led off
printf("led off\n");
delay(1000); // wait 1 sec
}
return 0;
}
5: Oprima la tecla Esc y escriba :w
6: Compilar y hacer el archivo ejecutable
$ gcc blink.c -o led -lwiringPi
7: Ejecutar
$ sudo ./led
8: Verifique la salida de lo GPIO:
Python Blink:
Conectar en el GPIO 40
import RPi.GPIO as GPIO import time pin = 21 # The pin connected to the LED iterations = 10 # The number of times to blink interval = .25 # The length of time to blink on or off GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(pin, GPIO.OUT) # The parameters to "range" are inclusive and exclusive, respectively, # so to go from 1 to 10 we have to use 1 and 11 (add 1 to the max) for x in range(1, iterations+1): print "Loop %d: LED on" % (x) GPIO.output(pin, GPIO.HIGH) time.sleep(interval) print "Loop %d: LED off" % (x) GPIO.output(pin, GPIO.LOW) time.sleep(interval)