| Electronic Components Datasheet Search |
|
DEV-12887 Datasheet(PDF) 20 Page - SparkFun Electronics |
|
|
|||||||||||||||||||||||||||||
DEV-12887 Datasheet(HTML) 20 Page - SparkFun Electronics |
|
20 / 40 page ![]() /* Digital Input, Analog Input, PWM Output Example by: Jim Lindblom SparkFun Electronics date: July 15, 2013 license: Beerware. Use, reuse, and modify this code howeve r you see fit. If you find it useful, buy me a beer some day! This is a simple piece of code which uses an LED, potentiom eter, and button. The LED connects to pin 1 through a 47 ohm resistor. The ca thode of the LED should connect to ground. This means writing pin 1 will turn the LED on, and wri ting it to 0 turns the LED off. The button connects on one side to pin 9, and the other pi n of the button goes to ground. We'll use the internal pullup resistors on pin 9 to b ias the button high. When the button is pressed, pin 9 should read as low. The wiper of the potentiometer is connected to pin 5. The o ther two pins of the pot should be connected to +3.3V and GND. This'll make the voltage a t pin 5 adjustable from 03.3V. */ //////////////////////////////////////// // Function definitions // //////////////////////////////////////// local ledState =1; // Says local, but think of this as a glob al var. Start with LED on // function pin9Changed() will be called whenever pin 9 goes f rom high>low or low>high function pin9changed() { local buttonState = hardware.pin9.read(); // Read from th e button pin if (buttonState == 0) // Button will read low if pressed { ledState = ledState ? 0: 1; // Flip flop ledState server.log("Button pressed!"); } else // Otherwise button was released, no action { server.log("Button released"); } } // Loop constantly updates the LED. If ledState is 1, we'll re ad the pot, and set the LED brightness accordingly. // If ledState is 0, we'll just turn the LED off. ledState is updated in the pin9Changed() function. function loop() { if (ledState == 1) { local rawValue = hardware.pin5.read(); // Read from t he potentiometer. Returns a value between 0 and 65535. rawValue /= 65535.0; // Make rawValue a % (and a floa t). The pin write function requires a value between 0 and 1. hardware.pin1.write(rawValue); // Pin 1 is already co nfigured as PWM, write potentiometer value Page 20 of 40 |
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |