Quick Links
Overview
The Papilio One QuickStart sketch is a “Hello World” example. You will need to use the ZAP IDE to modify the Papilio QuickStart Sketch.
The Quickstart sketch does the following:
- Blinks all of the even numbered pins.
- Configures all of the odd number pins as inputs. When a odd number pin is asserted it will cause the even pin next to it to stop blinking and stay at 3.3V.
- Sends the ASCII table at 9600 8N1 over the serial port in a continuous loop.
- The B/LED Wing can be plugged into any of the Wing Slots and the LED’s will be blinking. Pressing any of the buttons will cause the LED to stay lit while the button is pressed.
Code
/* Gadget Factory Papilio One QuickStart Example Pressing any of the 4 pushbuttons on the Button/LED Wing will light the corresponding LED. BPW5007 Button/LED Wing Reference: http://www.gadgetfactory.net/gf/project/bpw5007-butnled/ Hardware: * Connect a Button/LED Wing to any available Wing Slot created 2010 by Jack Gassett from existing Arduino code snippets http://www.gadgetfactory.net This example code is in the public domain. */ int ledPins[] = { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46 }; // an array of pin numbers to which LEDs are attached int ledCount = 24; // the number of pins (i.e. the length of the array) int buttonPins[] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47 }; // an array of pin numbers to which Buttons are attached int buttonCount = 24; // the number of pins (i.e. the length of the array) // variables will change: int buttonState = 0; // variable for reading the pushbutton status int thisPin; int ledState = LOW; // first visible ASCIIcharacter '!' is number 33: int thisByte = 33; // you can also write ASCII characters in single quotes. // for example. '!' is the same as 33, so you could also use this: //int thisByte = '!'; void setup() { // initialize the LED pins as an output: for (int thisPin = 0; thisPin < ledCount; thisPin++) { pinMode(ledPins[thisPin], OUTPUT); } // initialize the pushbutton pin as an input: for (int thisPin = 0; thisPin < ledCount; thisPin++) { pinMode(buttonPins[thisPin], INPUT); } //Setup Serial port and send out Title Serial.begin(9600); // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } void loop(){ //This sends the ASCII table to the serial port. // prints value unaltered, i.e. the raw binary version of the // byte. The serial monitor interprets all bytes as // ASCII, so 33, the first number, will show up as '!' //Serial.print(thisByte, BYTE); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. //this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) // also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if(thisByte == 126) { // you could also use if (thisByte == '~') { thisByte = 33; } // go on to the next character thisByte++; //This section blinks the LED's and keeps them solid if a button is pressed. delay(200); // wait for a second ledState = !ledState; for (int thisPin = 0; thisPin < buttonCount; thisPin++) { // read the state of the pushbutton value: buttonState = digitalRead(buttonPins[thisPin]); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPins[thisPin], HIGH); } else { // toggle LED: digitalWrite(ledPins[thisPin], ledState); } } }
Leave a Reply
You must be logged in to post a comment.