Книга: OpenMV Development Workshop
Назад: 5.1 Getting Started
Дальше: 5.3 Demo Analog Input (ADC): Working with Potentiometer

5.2 Demo Analog Output (PWM) : RGB LED

In this scenario we build a program to control RGB LED color using OpenMV Analog output (PWM). RGB LED has 4 pins that you can see it on Figure below.

p5_b1

To understand these pins, you can see the following Figure.

p5_b2

Note:


Now we can start to build a program and hardware implementation.


5.2.1 Wiring

For our testing, we configure the following PWM pins.


Here is a sample implementation with OpenMV and RGB Led.

o5-1


5.2.2 Writing Program

To display a certain color, we must combine colors from red, green, blue. OpenMV provides API for PWM using Timer and TimerChannel, http://docs.openmv.io/library/pyb.Timer.html. We set PWM value with input value from 0 to 1023. 

Regarding to Timer pinout, here’s the Timer Pinout:


Let's start to build a program in OpenMV IDE. The following is complete code.

from pyb import Pin, Timer import time   gpio_red = Pin('P0') gpio_green = Pin('P1') gpio_blue = Pin('P2')   def set_rgb(red, green, blue):     tim1 = Timer(1, freq=1000)      ch1 = tim1.channel(3, Timer.PWM, pin=gpio_red)     ch1.pulse_width_percent((red*100)/1023)      ch2 = tim1.channel(2, Timer.PWM, pin=gpio_green)     ch2.pulse_width_percent((green*100)/1023)      ch3 = tim1.channel(1, Timer.PWM, pin=gpio_blue)     ch3.pulse_width_percent((blue*100)/1023)      time.sleep(1500)     tim1.deinit()   print('print PWM with RGB led')  while 1:     print('red')     set_rgb(0, 1023, 1023)     print('green')     set_rgb(1023, 0, 1023)     print('blue')     set_rgb(1023, 1023, 0)     print('yellow')     set_rgb(0, 0, 1023)     print('purple')     set_rgb(700, 1023, 700)     print('aqua')     set_rgb(1023, 0, 0) 


o5-5

Save this program.

This program will generate six colors: red, green, blue, yellow, purple, and aqua.


5.2.3 Testing

Run the program. You should see several color on RGB LED.

o5-6


The following is a sample demo on RGB LED.

o5-2

o5-3

o5-7

o5-4



Назад: 5.1 Getting Started
Дальше: 5.3 Demo Analog Input (ADC): Working with Potentiometer

Kirajes
Здесь можно Suninat 50mg (Сунитиниб) - Сунинат (Sunitinib) - аналог Сутент купить. Лекарство назначают больным, страдающим от онкологии желудка, кишечника, поджелудочной железы, полипов толстой кишки, новообразований в почке и прочих злокачественных опухолей, связанных с желудочно-кишечным трактом. сутент купить +в москве