{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 11/26/2022 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F2221
Clock = 8
#option DIGITALIO_INIT = true // tell compiler to automatically call SetAllDigital
Include "setdigitalio.bas"
Include "intosc.bas"
#option SWORDFISH_SE = true
'Include "setdigitalio.bas"//Include "SetDigitalIO.bas"
Include "utils.bas"
Include "Convert.bas"
Dim Time_delay As longword
Dim X As Byte
//12 VOLT LED STRIPS
Dim R As PORTA.0
Dim Y As PORTA.1
Dim D As PORTA.2
Dim E As PORTA.3
Dim R_1 As PORTA.4
Dim W As PORTA.5
Dim O As PORTA.6
Dim D_1 As PORTA.7
Dim Red_Candle_STRIPS As PORTB.0 //turn on mosfet Q10
Dim Flames As PORTB.1 //TOGGLE SWITCH PORT
//CAKE SPRINKLES CATHODES USING MOSFETS mosfets ar? cycle through the COLUM (SPRINKLES) not the ROWS
Dim Row_4 As PORTB.2
Dim Row_3 As PORTB.3
Dim Row_2 As PORTB.4
Dim Row_1 As PORTB.5
//HEADLIGHT ON TRAIN ENGINE
Dim Head_light As PORTC.7
//CANDLE FLAMES
Dim Flame1 As PORTC.0
Dim Flame2 As PORTC.1
Dim Flame3 As PORTC.2
// SPRINKLES ANODES
Dim RED As PORTC.3
Dim WHITE As PORTC.4
Dim BLUE As PORTC.5
Dim GREEN As PORTC.6
Sub Sprinkles()
// CYCLE THROUGH ENABLING THE ANODES and rows
// LIGHT CANDLES
//CANDLE FLAMES ON SEQUENCLY PORTC. 0,1,2
Flame1 = 1
DelayMS(2000)
Flame2 = 1
DelayMS(2000)
Flame3 = 1
//Row_1
RED = 1
WHITE=0
BLUE = 0
GREEN = 0
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
//ROW_2
RED = 0
WHITE=0
BLUE = 1
GREEN = 0
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
//ROW_3
RED = 0
WHITE=0
BLUE = 1
GREEN = 0
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
//ROW_4
RED = 0
WHITE=0
BLUE = 0
GREEN = 1
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
End Sub
Sub Candles()
If Flames = 0 Then //toggle switch ON to ground
Flame1 = 1
DelayMS(1500)
Flame2 = 1
DelayMS(1500)
Flame3 = 1
EndIf
If Flames = 1 Then //toggle switch off disconnects ground
Flame1 = 0 //turn these on sequently maybe 1500ms delay between each flane
Flame2 = 0
Flame3 = 0
EndIf
End Sub
Sub Head_light_Motion() //needs work to flicker
Head_light = 1
DelayMS(250)
Head_light = 0
DelayMS(400)
Head_light = 1
DelayMS(400)
End Sub
// before enabling the outputs, init all LAT registers low
LATA = 0
LATB.0 = 0
LATB.1 = 1
LATB.2 = 0
LATB.3 = 0
LATB.4 = 0
LATB.5 = 0
LATB.6 = 0
LATB.7 = 0
LATC = 0
//ENABLE OUTPUTS port A, B, C
TRISA = 0
TRISB.0 = 0
TRISB.1 = 1 //input
TRISB.2 = 0
TRISB.3 = 0
TRISB.4 = 0
TRISB.5 = 0
TRISB.6 = 0
TRISB.7 = 0
TRISC = 0
//SPRINKLES COLUMS
RED = 0
WHITE=0
BLUE = 0
GREEN = 0
Input(Flames)
// MAKE ALL THE CATHODES LOW
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 1
Head_light = 0 //TOGGLETO SIMULATE MOVEMENT
//TURN OFF THE LETTERING
R = 0
Y = 0
D = 0
E = 0
R_1 = 0
W = 0
O = 0
D_1 = 0
//TURN OFF THE RED STRIPS
Red_Candle_STRIPS = 0
// TURN OFF FLAMES
Flame1 = 0 //portC.0
Flame2 = 0 //portC.1
Flame3 = 0 //portC.2
Input(Flames) //connects to ground via toggle switch connected to portb.1 (flames)
time_delay = 0
'Z = 0
SetAllDigital()
While true
// Lettering comes on sequently 6 times
// z = 0
repeat
R = 1 //turn on lettering sequencly
DelayMS(1500)
Y = 1
DelayMS(1500)
D = 1
DelayMS(1500)
E = 1
DelayMS(1500)
R_1 = 1
DelayMS(1500)
W = 1
DelayMS(1500)
O = 1
DelayMS(1500)
D_1 = 1
DelayMS(1500)
For X = 0 To 5 //blink lettering 6 times
R = 0
Y = 0
D = 0
E = 0
R_1 = 0
W = 0
O = 0
D_1 = 0
DelayMS(1500)
R = 1
Y = 1
D = 1
E = 1
R_1 = 1
W = 1
O = 1
D_1 = 1
DelayMS(1500)
Next
Head_light_Motion() //turn on headlight
//TURN ON THE RED LED STRIPS (100 ON TOP OF CAKE)
Red_Candle_STRIPS = 1 //turn on the red 100 on top of cake
time_delay = time_delay + 1
until
time_delay = 240000 // 4 minutes when say 4 minutes have passed then the code recycles again
if flames = 0 then // enable candle flames sequencing
candles()
end if
Wend
time_delay = 0
repeat
DelayMS(1500)
DelayMS(1500)
DelayMS(1500)
DelayMS(1500)
DelayMS(1500)
DelayMS(1500)
DelayMS(1500)
DelayMS(1500)
For X = 0 To 5
DelayMS(1500)
DelayMS(1500)
Next
time_delay = time_delay + 1
until time_delay = 240000 // 4 minutes when say 4 minutes have passed then the code recycles again
The OP has not plans on becoming a professional programmer, and even if he did, are there other languages he shouldn't use? It's not the tool, it's the person in front of the keyboard.If you have any plans of doing a lot with microcontroller and especially if you have any idea of doing so professionally, please abandon swordfish and learn C.
Obviously, 240,000 is 4 minutes worth of milliseconds.What in god's name would make you think that loop takes 4 minutes?
I would imagine they earn nothing from it, as they are free. As you 'corrected' they are written in C++, not C, which is what makes them so easy to use - and complicates things trying to port Arduino libraries to PIC'sI find it interesting that ALL the Arduino libraries are written in C (actually C++) and I wonder who will write those libraries in the future. Bet they'll earn a fortune.
They currently get nothing but their skill set is becoming more rare and I assume they will become more in demand. Plus, I doubt they don't earn from it as the chip manufacturer (or whatever the library is for) must employ these people to write the libraries. The fact WE get them for free does not mean the programmer didn't get paid.I would imagine they earn nothing from it, as they are free.
No, the libraries are almost entirely written by the public, for their own use and then shared - a few, like SparkFun ones, are written by programmers within the company, in order to promote products they sell that use the libraries.They currently get nothing but their skill set is becoming more rare and I assume they will become more in demand. Plus, I doubt they don't earn from it as the chip manufacturer (or whatever the library is for) must employ these people to write the libraries. The fact WE get them for free does not mean the programmer didn't get paid.
Mike.
If that is true then once all the programmers that can write libraries are "gone", who will write them? Must admit, I've written one such library without getting payed but just keep it to myself.No, the libraries are almost entirely written by the public, for their own use and then shared
Why will they be 'gone'? - there's a never ending stream of new programmers coming along - while C/C++ is an older language now, more modern languages are very similar, and it would be easy for future programmers to use C/C++ if there was any need to.If that is true then once all the programmers that can write libraries are "gone", who will write them? Must admit, I've written one such library without getting payed but just keep it to myself.
Mike.
counter = 0
repeat
delayms(30000) // 30 secs
counter = counter + 1
until counter = 240000
dim time_delay as longword
// wait 't' msecs and incr global 'time_delay' variable
sub wait_delay(t as word)
delayms(t)
time_delay = time_delay + t
end sub
time_delay = 0
repeat
// add your led statements and change all the calls to 'delayms()' to:
wait_delay(1500)
// other leds...
until (time_delay >= 240000)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?