View previous topic :: View next topic |
Author |
Message |
pinkfloyd11
Joined: 02 Jul 2007 Posts: 247
|
Posted: Sat Dec 13, 2014 9:48 am Post subject: Arduno Like Library: new idea for Bascom user |
|
|
Hello
my idea is simple: write library in bascom with the same "style" used in Arduino.
If anyone of us write one or more "Arduino Like Library" we could have rich archive in few time.
It could be still better if we could have list of this library directly in IDE (Code Project - PDF viewer -...- Arduino Like Library )
Here my Idea
Code: | '************************************************************************************
' Arduino Like Library
'************************************************************************************
' NAME: RGB LED
' VERSION: 1.0
' AUTHOR: Giuseppe Pezzella
' SPECIAL THANKS: bzijlstra
'...................................................................................................................................................................................................................
' HARDWARE PERIPHERALS: Timer 0, Timer 1, Timer 2
' PINOUT ATMEL: (PB.1-GREEN ANODE) (PB.3-RED ANODE) (PD.6-BLUE ANODE)
' PINOUT ARDUINO UNO: (9-GREEN ANODE) (6-RED ANODE) (11-BLUE ANODE)
' LIBRARY METODE:
' -----> START_RGB_LED: Start Timer that drive LED
' -----> STOP_RGB_LED: Stop Timer that drive LED
' -----> RGB_LED_COLOR: Set color to RGB LED
'************************************************************************************
Config SUBMODE = NEW
$regfile = "m328pdef.dat"
$hwstack = 32
$swstack = 32
$framesize = 32
$crystal = 16000000
$Include "RGB Library.inc"
Dim Random1 as byte
Dim Random2 as byte
Dim Random3 as byte
DO
START_RGB_LED
Random1 = rnd(255)
Random2 = rnd(255)
Random3 = rnd(255)
RGB_LED_COLOR Random1, Random2, Random3
Wait 1
STOP_RGB_LED
LOOP
END |
Code: | '*********************************
'Timer configured as PWM
'*********************************
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
Red_pwm Alias Pwm0a
Green_pwm Alias Pwm1a
Blue_pwm Alias Pwm2a
Config Portb.3 = Output 'RED LED
Config Portb.1 = Output 'GREEN LED
Config Portd.6 = Output 'BLUE LED
Stop TIMER0
Stop TIMER1
Stop TIMER2
'*********************************
'_______________________________________________________________________
SUB RGB_LED_COLOR (Red_Color as byte, Green_Color as byte, Blue_Color as byte)
Red_pwm = Red_Color
Green_pwm = Green_Color
Blue_pwm = Blue_Color
END SUB
'_______________________________________________________________________
SUB START_RGB_LED
Start TIMER0
Start TIMER1
Start TIMER2
END SUB
'_______________________________________________________________________
SUB STOP_RGB_LED
Stop TIMER0
Stop TIMER1
Stop TIMER2
END SUB
'_______________________________________________________________________ |
(BASCOM-AVR version : 2.0.7.7 )
Last edited by pinkfloyd11 on Sat Dec 13, 2014 2:12 pm; edited 1 time in total |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sat Dec 13, 2014 11:32 am Post subject: |
|
|
Hello pinkfloyd11
This is what I have been trying to do with my projects as much as possible.
By making the subs and functions separate .INC files so all you do is include them
with submode new they do not have to be declared
I wanted to add to the Wiki but I keep timing out so can not navigate through it
I have this problem with the forum but not as bad I think it is more to do with my ISP.
If people adopt the project mode and use Local variables as much as possible then the code in the .INC files would become portable.
Regards Paul |
|
Back to top |
|
|
pinkfloyd11
Joined: 02 Jul 2007 Posts: 247
|
Posted: Sat Dec 13, 2014 2:16 pm Post subject: |
|
|
Hi Paul
extract from your project piece of code that could be reused from us and post here...
I invite all to post here their piece of code
Giuseppe |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
aphawk
Joined: 23 Jan 2010 Posts: 168 Location: Brazil
|
Posted: Mon Dec 15, 2014 2:49 am Post subject: |
|
|
I think that we must create a standard for this, because in Arduino's code we need to declare the pins that will be used for the functions on libraries.
This definitions must be passed in the init code to the library.
I have made many codes for peripherals that can be converted to libraries, but someone ( maybe Mark ??? ) must create one stardard
to all people follows, and this can be very usefull to all kind of users.
But everyone must follows this when creating one library.
Paulo
Last edited by aphawk on Mon Dec 15, 2014 7:01 pm; edited 2 times in total |
|
Back to top |
|
|
Deanus
Joined: 26 May 2006 Posts: 188 Location: Adelaide
|
Posted: Mon Dec 15, 2014 9:00 am Post subject: |
|
|
Hi All,
Arn't you lot in the wrong section here since there is already a section for BASCOM-ARDUINO in the main menu.
BASCOM-ARDUINO
A forum to discuss using BASCOM-AVR with ARDUINO hardware. Notice that this is a USER forum. It is for users, by users. MCS Electronics provides this as a free service. This is NOT the support system which is at http://www.mcselec.com/support-center/
Moderator Duval JP
Dean |
|
Back to top |
|
|
|