Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Arduno Like Library: new idea for Bascom user

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
pinkfloyd11

Bascom Member



Joined: 02 Jul 2007
Posts: 248

italy.gif
PostPosted: Sat Dec 13, 2014 9:48 am    Post subject: Arduno Like Library: new idea for Bascom user Reply with quote

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
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1120
Location: SYDNEY

australia.gif
PostPosted: Sat Dec 13, 2014 11:32 am    Post subject: Reply with quote

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
View user's profile
pinkfloyd11

Bascom Member



Joined: 02 Jul 2007
Posts: 248

italy.gif
PostPosted: Sat Dec 13, 2014 2:16 pm    Post subject: Reply with quote

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
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 607

poland.gif
PostPosted: Sat Dec 13, 2014 5:19 pm    Post subject: Reply with quote

Yes for Include and Sub Mode = New because only used Subs are compiled from included files Very Happy
But no for using three timers for human eye Laughing

Code is not mine
Code:
$regfile = "m328pdef.dat"
$crystal = 16000000

Config Timer0 = Timer , Prescale = 8
Enable Timer0 : On Timer0 Timer0_isr
Enable Interrupts

Rd Alias Portb.0                                            'any pin
Gd Alias Portb.1                                            'any pin
Bd Alias Portb.2                                            'any pin

Dim Count As Byte
Dim Rled As Byte , Bled As Byte , Gled As Byte

Rled = 80                                                   'value in %
Gled = 0                                                    'value in %
Bled = 90                                                   'value in %

'*** START ***
Do


Loop
End
'*** END ***

Timer0_isr:
 Incr Count
 If Count = 100 Then Count = 0

 If Count < Rled Then Set Rd Else Reset Rd
 If Count < Gled Then Set Gd Else Reset Gd
 If Count < Bled Then Set Bd Else Reset Bd
Return
 
Back to top
View user's profile Visit poster's website
aphawk

Bascom Member



Joined: 23 Jan 2010
Posts: 152
Location: Brazil

brazil.gif
PostPosted: Mon Dec 15, 2014 2:49 am    Post subject: Reply with quote

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
View user's profile
Deanus

Bascom Member



Joined: 26 May 2006
Posts: 188
Location: Adelaide

australia.gif
PostPosted: Mon Dec 15, 2014 9:00 am    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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