| поискавой системы для электроныых деталей |
|
DEV-12887 датащи(PDF) 21 Page - SparkFun Electronics |
|
|
|||||||||||||||||||||||||||||
DEV-12887 датащи(HTML) 21 Page - SparkFun Electronics |
|
21 / 40 page ![]() } else { hardware.pin1.write(0); // Write pin 1 low LED off } // This must be called at the end. This'll call loop() aga in in 10ms, that way it'll actually loop! imp.wakeup(0.01, loop); } //////////////////////////////////////// // Setup Stuff: Runs first at startup // //////////////////////////////////////// hardware.pin1.configure(PWM_OUT, 0.0005, 0.0); // Configure Pin 1 as PWM output, 5ms period, 0% high (off) hardware.pin5.configure(ANALOG_IN); // Configure pin 5 as anal og input hardware.pin9.configure(DIGITAL_IN_PULLUP, pin9changed); // Co nfigure pin 9 as digital input (with pullup enabled). On chan ge it'll call function pin9changed(). imp.configure("LED Trigger Wiper", [], []); loop(); // Call loop, and let the program go! The code creates an adjustable-brightness LED controller. The brightness of the LED is adjusted by turning the potentiometer. Pressing the button will turn the LED on and off. Explaining the Code The skeleton of this code acts a lot like that of Hello, blink. The function definitions are up top, the setup stuff runs at the bottom, and loop() is called at the beginning. loop() continually calls itself, using the imp.wakeup(0.01, loop) function call, every 10 ms. The loop() function again relies on an ledState variable. If ledState is 1, we read the potentiometer voltage, and adjust the brightness of our LED accordingly. The ledState variable is flip-flopped in the pin9changed() function. This is like an interrupt. It’s called whenever the state of pin 9 changes – if it goes from high to low, or low to high. When setting up pin 9 as a digital input, we added this function as the one to be called when the state change occurred. Check out the comments in the code for a more in-depth overview of each function call. Or, for more information, check out Electric Imp’s API reference. Enough hardware stuff! The next two examples will make use of the imp’s greatest feature…it’s web connectivity. Example 2: Web Control (Request) Some of the most fun you can have with the imp is connecting it to the Internet, and interfacing it with web pages. In this example, we’ll use a simple HTML/Javascript web page to control some LEDs connected to the imp. This time, we’ll not only be writing code for the imp, but the agent as well. This example code will show how to pass data from the imp to the agent, and how to write a simple web page to interact with the agent half of the code. Page 21 of 40 |
|
ссылки URL |
| Вашему бизинису помогли Аллдатащит? [ DONATE ] |
Что такое Аллдатащит | реклама | контакт | Конфиденциальность | Ссылка на техническое описание | обмен ссыками | поиск по производителю 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 |