Paso 3: Y ahora el código
/******************************************************************** * Template for programming the Pibrella from PiMoRoNi in C. * * Dependencies: The wiringPi C libraries must be installed. * Instructions for download, install and use * are located at wiringpi.com * * Compile with: gcc -o [FILENAME] [FILENAME].c -lwiringPi * * Some of the more advanced features require additional #include * statements and Linking additional libraries. * * Run with: sudo ./[FILENAME] * ********************************************************************/
#include <wiringPi.h>
/****************************************************************** * LEDs ******************************************************************/ int ledR = 2; // Red int ledY = 0; // Yellow int ledG = 7; // Green int led[] = {2,0,7}; // Red, Yellow, Green - Array of LEDs. /******************************************************************* * Outputs - There are four output pins marked E, F, G and H. * There are two female connectors for each output. * The connector closest to the red button is the pin (positive). * The other connection is the ground * Each output pin has a status led which lights when the pin is high. ******************************************************************/ int outE = 3; int outF = 4; int outG = 5; int outH = 6; int out[] = {3,4,5,6}; // E, F, G, H - Array of outputs.
/***************************************************************** * Inputs - There are four input pins marked A, B, C and D. * There are two female connectors for each input. * The pin closest to the Red button is the digital input * and the other is + 3.3 volts. * There is an onboard pull down resistor on each input. * Using a switch to short directly to +3.3 volts is okay. * A resistive sensor (photocell) will switch the pin to high when * when the resistance is less than approximentally 30k. * Each input pin has a status led which lights when the pin is high. *****************************************************************/ int inA = 13; int inB = 11; int inC = 10; int inD = 12; int in[] = {13,11,10,12}; // A, B, C, D - Array of Inputs. // Onboard button int BUTTON = 14; //Button has an onboard pull down resistor. // Onboard buzzer int BUZZER = 1;
/**************************************************************** * setup() function, sets all the pinModes for the Pibrella ****************************************************************/ void setup(void) { int i; // Index for for loops. wiringPiSetup(); // Some WiringPi functions require sudo access. // Use wiringPiSetup(). for(i=0;i<3;i++) pinMode(led[i], OUTPUT); for(i=0;i<4;i++) pinMode(out[i], OUTPUT); for(i=0;i<4;i++) pinMode(in[i], INPUT); pinMode(BUTTON, INPUT); pinMode(BUZZER, OUTPUT); }
/******************************************************************* * loop() function, runs in continuous loop when setup finishes. * * <<< YOUR CODE GOES HERE >>> * *******************************************************************/ void loop(void) { // This is sample code, you can delete it // and write your own loop()function here. // In this example the red LED will light // if input A is shorted to +3.3 volts, if(digitalRead(inA)==HIGH) digitalWrite(ledR, HIGH); else digitalWrite(ledR, LOW); // and the green LED will light if the button is pressed. if(digitalRead(BUTTON)==HIGH) digitalWrite(ledG, HIGH); else digitalWrite(ledG, LOW); }
/******************************************************************* * main() function, required in all programs. *******************************************************************/ int main(void) { setup(); while(1) // Do this forever. { loop(); } return 0; }