View previous topic :: View next topic |
Author |
Message |
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Sun Sep 07, 2014 7:28 pm Post subject: Arduino Nano and PWM on a RGB-led |
|
|
No rocket-science but nice to show PWM testprogram for a RGB-led
The RGB-led on a PCB. R G B labeling not correct. But no problem.
Three different colors. In this example an ETT Arduino Nano compatible is used. With an Atmega168.
Code: |
' PWM op Arduino Nano atmega168 with RGB led
$regfile = "m168def.dat" ' specify the used micro
$crystal = 16000000 ' used crystal frequency
$hwstack = 32
$swstack = 32
$framesize = 32
$baud = 9600
Red_pwm Alias Pwm0a
Green_pwm Alias Pwm1a
Blue_pwm Alias Pwm2a
Config Timer0 = Pwm , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_down , Prescale = 1
Config Timer1 = Pwm , Pwm = 8 , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_down , Prescale = 1
Config Timer2 = Pwm , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_down , Prescale = 1
Config Portb.3 = Output 'red
Config Portb.1 = Output 'green
Config Portd.6 = Output 'blue
Dim X As Byte
Print Chr(27) ; "[2J" 'ANSI CLS goto 0/0
Print "Arduino Nano Atmega168 RGB PWM Example"
Print
Red_pwm = 0
Green_pwm = 0
Blue_pwm = 0
Print
Print "test RED"
For X = 1 To 255
Red_pwm = X
Waitms 10
Next X
Red_pwm = 0
Print
Print "test GREEN"
For X = 1 To 255
Green_pwm = X
Waitms 10
Next X
Green_pwm = 0
Print
Print "test BLUE"
For X = 1 To 255
Blue_pwm = X
Waitms 10
Next X
Blue_pwm = 0
Print
Print "All RGB colors together"
For X = 1 To 255
Red_pwm = X
Green_pwm = X
Blue_pwm = X
Waitms 10
Next X
Red_pwm = 0
Green_pwm = 0
Blue_pwm = 0
Print
Do
Input "Give PWM value for RED (0 - 255) " , X
Red_pwm = X
Print
Input "Give PWM value for GREEN (0 - 255) " , X
Green_pwm = X
Print
Input "Give PWM value for BLUE (0 - 255) " , X
Blue_pwm = X
Print
Loop
End
|
Three separate timers are used.
And here the images on a mini-scope
PWM 50 and PWM 200 used.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Mon Sep 08, 2014 3:28 pm Post subject: |
|
|
good !
I use it with the lcd display 16*2 from DFrobot , the light is drived by a PWM:
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portb.1 , Rs = Portb.0
Config Lcd = 16 * 2
Enable Interrupts
Config Pinb.2 = Output ' Timer 1 for PWM
Config Timer1 = Pwm , Pwm = 10 , Prescale = 1 , Compare B Pwm = Clear Up
'the output for PWM1 is PB1 (OC1A) and PB2 (OC1B) here we use OC1B
Pwm1b = 200 'you can change the light by increasing or decreasing it, max 255
many thanks
JP |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|