Tonight I ran a one off D&D game for some friends. They took on
Tiamat and destroyed her pretty decisively in less than 2 combat rounds.
They each constructed two 20th Level characters, with a small pile of
magic items each. The video is 48 minutes, if you want to see how
D&D is being played in this modern age, check it out.
The public executioner at Rome, who executed persons of the lowest rank; hence, an executioner or hangman.
Friday, July 31, 2020
Friday, July 24, 2020
Simple Encryption with MMBasic
The program presented here is a very simple encryption program, one I have written several times over the years to relearn Basic. This program takes advantage of two built in functions, RND and XOR.
RND is a pseudo random number generator, I say pseudo because it is not a true random number generator. The function needs to be seeded with a number, which it then uses to generate other numbers. If you seed the function with the same number, it will generate the same numbers. To make this appear more random, Basic programmers often seed the function with the Timer function, which seeds RND with the number of seconds past midnight. In this program, I take the password entered, convert each letter to its ASCII number and add them all together and then seed the RND function with this number. The result of this is, each time you enter the same password, the RND function will use the same set of numbers to encrypt or decrypt the message.
XOR is a simple formula that always produces the same 3 numbers. For instance, 1 XOR 2 = 3, 2 XOR 3 = 1, 3 XOR 1 = 2. In this program, I am generating a number using the RND function, then I am taking the letters from the file I want to encrypt, one at a time and converting it to its ASCII number. I am then XOR'ing the two numbers, converting that number into text and writing it to a file. For instance say the RND function generates 35 and the letter from my file a small case "a". The ASCII values of small case "a" is 97. 35 XOR 97 = 33, I then convert 33 to its ASCII text equivalent, which is "!" and I write that to the encrypted file. Re-running the program, this time using the encrypted file as the file you want to encrypt, the process reverses itself. The RND function will produce the same number, 35, and it will read the "!", convert it to its ASCII value of 33, then XOR the two numbers (35 XOR 33 = 97), to produce 97 and convert this number to its ASCII text value of small case "a" and writes that to the decrypted file.
' encrypt.bas
' Uses the RND and XOR functions to encrypt text files
Input "Password: ", Password$
Print
For Count = 1 To Len(Password$)
MyNumber = MyNumber + Asc(Left$(Password$,Count))
Next
Randomize MyNumber
Input "Enter File to be encrypted: ", FileName$
Print
Open FileName$ For Input As #1
Input "Enter the name to save the encryted file as: ", EncryptedFile$
Print
Open EncryptedFile$ For OutPut As #2
Print "Encrypting the file, please wait..."
Print
For Count = 1 To Lof(#1)
Print ".";
RealPassword = Int(Rnd * 126) + 1
Temp$ = Input$(1,#1)
Encrypt = RealPassword Xor Asc(Temp$)
If Encrypt < 1 Then Encrypt = Encrypt + 126
If Encrypt > 126 Then Encrypt = Encrypt - 126
Encrypt$ = Chr$(Encrypt)
Print #2, Encrypt$;
Next Count
Close #1
Close #2
Print "Done"
Print
End
Okay, let me make this very clear, this is not a strong encryption by any means, in fact by today's standards, it is barely encryption at all. A low level NSA mook could break this on his coffee break, and even a scrub hacker could break this in an hour using his grandma's computer. The only person this will protect you from is your 12 year old sister, and I would not even bet on that.
The point of this program is simply to teach the basics of encryption, using functions readily available in the Basic programming language. The security can be increased by building your own equivalent functions to RND and XOR using more mathematically complex and security sound formulas. You could also use the RND function to find a location within a key file, say a jpeg image, and use the bit at that location to XOR with the letters needing encrypting and save the file as a binary file rather than a text file. The point of course is, this is just a starting point.
_______________________________________________________________
Edit:
The reason this is not considered secure encryption is because the possible combination of numbers is low by the standards of modern computing. We have three numbers, the psuedo random number generated by RND, the ASCII number of the letter to be encrypted and the ASCII number of the encrypted letter. In theory, this gives us 126x126x126=2,000,376 possible combinations, this is a pretty big number, but not a huge number when you consider that an old 1.8Ghz desktop computer can execute 1,800,000,000 computations per second, that means it takes about .001 seconds to go through all of them for a single letter, that is not much. Now, the reality is, we already know 1 of the three numbers, the encrypted letter, so all we have to do is find the other two, now we are only looking at 128x128=15,876 combinations, now we are talking .000009 seconds for each letter. So the file you are trying to protect would have to be gargantuan to take any significant amount of time to break.
RND is a pseudo random number generator, I say pseudo because it is not a true random number generator. The function needs to be seeded with a number, which it then uses to generate other numbers. If you seed the function with the same number, it will generate the same numbers. To make this appear more random, Basic programmers often seed the function with the Timer function, which seeds RND with the number of seconds past midnight. In this program, I take the password entered, convert each letter to its ASCII number and add them all together and then seed the RND function with this number. The result of this is, each time you enter the same password, the RND function will use the same set of numbers to encrypt or decrypt the message.
XOR is a simple formula that always produces the same 3 numbers. For instance, 1 XOR 2 = 3, 2 XOR 3 = 1, 3 XOR 1 = 2. In this program, I am generating a number using the RND function, then I am taking the letters from the file I want to encrypt, one at a time and converting it to its ASCII number. I am then XOR'ing the two numbers, converting that number into text and writing it to a file. For instance say the RND function generates 35 and the letter from my file a small case "a". The ASCII values of small case "a" is 97. 35 XOR 97 = 33, I then convert 33 to its ASCII text equivalent, which is "!" and I write that to the encrypted file. Re-running the program, this time using the encrypted file as the file you want to encrypt, the process reverses itself. The RND function will produce the same number, 35, and it will read the "!", convert it to its ASCII value of 33, then XOR the two numbers (35 XOR 33 = 97), to produce 97 and convert this number to its ASCII text value of small case "a" and writes that to the decrypted file.
' encrypt.bas
' Uses the RND and XOR functions to encrypt text files
Input "Password: ", Password$
For Count = 1 To Len(Password$)
MyNumber = MyNumber + Asc(Left$(Password$,Count))
Next
Randomize MyNumber
Input "Enter File to be encrypted: ", FileName$
Open FileName$ For Input As #1
Input "Enter the name to save the encryted file as: ", EncryptedFile$
Open EncryptedFile$ For OutPut As #2
Print "Encrypting the file, please wait..."
For Count = 1 To Lof(#1)
Print ".";
RealPassword = Int(Rnd * 126) + 1
Temp$ = Input$(1,#1)
Encrypt = RealPassword Xor Asc(Temp$)
If Encrypt < 1 Then Encrypt = Encrypt + 126
If Encrypt > 126 Then Encrypt = Encrypt - 126
Encrypt$ = Chr$(Encrypt)
Print #2, Encrypt$;
Next Count
Close #1
Close #2
Print "Done"
End
Okay, let me make this very clear, this is not a strong encryption by any means, in fact by today's standards, it is barely encryption at all. A low level NSA mook could break this on his coffee break, and even a scrub hacker could break this in an hour using his grandma's computer. The only person this will protect you from is your 12 year old sister, and I would not even bet on that.
The point of this program is simply to teach the basics of encryption, using functions readily available in the Basic programming language. The security can be increased by building your own equivalent functions to RND and XOR using more mathematically complex and security sound formulas. You could also use the RND function to find a location within a key file, say a jpeg image, and use the bit at that location to XOR with the letters needing encrypting and save the file as a binary file rather than a text file. The point of course is, this is just a starting point.
_______________________________________________________________
Edit:
The reason this is not considered secure encryption is because the possible combination of numbers is low by the standards of modern computing. We have three numbers, the psuedo random number generated by RND, the ASCII number of the letter to be encrypted and the ASCII number of the encrypted letter. In theory, this gives us 126x126x126=2,000,376 possible combinations, this is a pretty big number, but not a huge number when you consider that an old 1.8Ghz desktop computer can execute 1,800,000,000 computations per second, that means it takes about .001 seconds to go through all of them for a single letter, that is not much. Now, the reality is, we already know 1 of the three numbers, the encrypted letter, so all we have to do is find the other two, now we are only looking at 128x128=15,876 combinations, now we are talking .000009 seconds for each letter. So the file you are trying to protect would have to be gargantuan to take any significant amount of time to break.
Tuesday, July 21, 2020
Colour Maximite Thoughts
Recently at the Backshed forums, which is the primary community for the Maximite system, a user suggested a database library which could then be used to develop database applications. There was a minor discussion about it, but ultimately there was simply not enough interest in the project and the original poster ended the discussion with some snark, saying
"It doesn't look like very many people see a need for it and are interested in using it. I certainly am not going to bother writing it if nobody wants or needs it. No matter, the CMM2 will do a great job of teaching youngsters how to fire bazookas at boogymen and androids."
While I cannot fault him for the statement, I think the real problem is the OP's fundamental misunderstanding of what the Colour Maximite series of machines are really being used for. The Maximite is not a desktop computer, it is not the type of machine you use to surf the web, check your email and create documents. Even the newest version is based on a 400Mhz ARM processor and has only a few megabytes of RAM. On top of that, MMBasic is not a true operating system, it is a programing language that serves some of the functions of an operating system.
What the Maximite is, is a development platform that falls somewhere between an Arduino and a Rasperry Pi. The end goal for these things is to provide an environment similar to that of a Commodore 64 and other computers of its era.Additionally, a set of GPIO pins have been provided so the hardware can be extended with relative ease. It is far more flexible than an Arduino, as well as easier to use. It is also far less daunting than a Raspberry Pi for small projects and does not have the overhead of a full blown Linux operating system.
If you go back and look at what people were using those Commodore 64's for, it was not writing letters, doing homework or tracking receipts, although I suspect many parents were convinced to buy them for these purposes. No, the primary use for those machines was to play games. Almost every kid who had one of these machines, also learned to do at least a little bit of coding in Basic, because you pretty much had to to use the bloody thing.
The Maximite is no different, no one is going to develop productivity applications for the Maximite, not even a simple text editor. It is not because it cannot be done, it can be. The problem is, there is no point, in this day and age, virtually everyone has a desktop computer at home. Don't give me any bullshit about some people cannot afford computers, which is true, but if you cannot afford a computer, then you sure as shit cannot afford a Maximite and you should be using that money for food and rent. But seriously, what is the point of developing a database library for the Maximite, when I have several good options available to me on my desktop computer. I don't need the Maximite for productivity applications, I already have a computer for that stuff. Those wheels have already been invented and they are running on hardware that is superior to the Maximite by several magnitudes.
The last thing I have to say about this is, if the OP wants to develop a database library for the Maximite, he should go a head and do it. However, he should do it because he has a use for it and because he wants to do it and because he will enjoy doing it. Ultimately basing his decision to do it or not on whether or not other people needed it, tells me even he did not think it was a great idea, otherwise he would have just done it.
"It doesn't look like very many people see a need for it and are interested in using it. I certainly am not going to bother writing it if nobody wants or needs it. No matter, the CMM2 will do a great job of teaching youngsters how to fire bazookas at boogymen and androids."
While I cannot fault him for the statement, I think the real problem is the OP's fundamental misunderstanding of what the Colour Maximite series of machines are really being used for. The Maximite is not a desktop computer, it is not the type of machine you use to surf the web, check your email and create documents. Even the newest version is based on a 400Mhz ARM processor and has only a few megabytes of RAM. On top of that, MMBasic is not a true operating system, it is a programing language that serves some of the functions of an operating system.
What the Maximite is, is a development platform that falls somewhere between an Arduino and a Rasperry Pi. The end goal for these things is to provide an environment similar to that of a Commodore 64 and other computers of its era.Additionally, a set of GPIO pins have been provided so the hardware can be extended with relative ease. It is far more flexible than an Arduino, as well as easier to use. It is also far less daunting than a Raspberry Pi for small projects and does not have the overhead of a full blown Linux operating system.
If you go back and look at what people were using those Commodore 64's for, it was not writing letters, doing homework or tracking receipts, although I suspect many parents were convinced to buy them for these purposes. No, the primary use for those machines was to play games. Almost every kid who had one of these machines, also learned to do at least a little bit of coding in Basic, because you pretty much had to to use the bloody thing.
The Maximite is no different, no one is going to develop productivity applications for the Maximite, not even a simple text editor. It is not because it cannot be done, it can be. The problem is, there is no point, in this day and age, virtually everyone has a desktop computer at home. Don't give me any bullshit about some people cannot afford computers, which is true, but if you cannot afford a computer, then you sure as shit cannot afford a Maximite and you should be using that money for food and rent. But seriously, what is the point of developing a database library for the Maximite, when I have several good options available to me on my desktop computer. I don't need the Maximite for productivity applications, I already have a computer for that stuff. Those wheels have already been invented and they are running on hardware that is superior to the Maximite by several magnitudes.
The last thing I have to say about this is, if the OP wants to develop a database library for the Maximite, he should go a head and do it. However, he should do it because he has a use for it and because he wants to do it and because he will enjoy doing it. Ultimately basing his decision to do it or not on whether or not other people needed it, tells me even he did not think it was a great idea, otherwise he would have just done it.
Sunday, July 19, 2020
Tiananmen Square of our Time
Last night during protests in Portland, where federal forces have been deployed to quell the rebellion, a woman who has been dubbed "Naked Athena" stood completely nude in front of federal agents who were blocking a street to keep protestors from advancing. After attempting to warn her off for several minutes, the federal agents withdrew.
This showdown reminded me somewhat of the Tiananmen Square protests in China in 1989, that produced this bit of history.
This just goes to show, what one brave person can do in the face of tyranny.
This showdown reminded me somewhat of the Tiananmen Square protests in China in 1989, that produced this bit of history.
This just goes to show, what one brave person can do in the face of tyranny.
Saturday, July 11, 2020
My Basic Programs for the Maximite
I have started placing all the basic programs I write for this website on my Google drive and made it public. This is for those of you who do not want to type them in by had. Personally, I think you should type them in by hand, especially if you are just learning to program in MMBasic. Typing in the programs is a good way to start learning and retaining computer programing. Besides that, most of these programs are fairly short. So if you have been following my tutorials and such, the programs are here;
Google Drive Link
As I progress, I will add more to the drive.
The Practical Maximite Part 3
In this tutorial we are going to learn how to take advantage of the Arduino compatibility of the Maximite. All of the Colour Maximites have the headers, but not al of them have the sockets soldered in. Mine came with the sockets, if yours did not, you will have to stop here.
When I was making the choice as to what Arduino hat I wanted for my Maximite, it was actually a pretty easy choice. An LCD hat gives you another readable output, which is good for a number of things like error capturing when debugging programs and providing secondary information. These also provide you with a set of buttons that you can use to trigger events. The hat I got can be found here; 16x2 LCD Keypad Shield 1602. These hats are made by many companies, are readily available and are cheap, since you can generally get them for under $10. Make sure if you are buying one of these from a different manufacturer, that is is built on a HD44780 LCD chip, MMBasic has built in support for this chipset.
There are a couple of caveats with these hats, first, there is a reset button, this is handy for resetting your Maximite if, like me, you do not have a power switch. The downside is, if you accidentally press it, you will loose any unsaved programs you have in memory, so be careful and save often. Second, there is a select button, this does not work, it is hooked up to the 5 volt rail, but I have no idea what Pin it is connected to. Lastly, if at first you cannot get anything to display, the contrast is probably set way too low. The contrast is controlled by a screw on top of the blue plastic thing in the upper left corner of the hat. Give the screw 10 complete turns clockwise, and that should make your text become visible and you can adjust to taste from there.
Now, lets get on with doing useful things with this hat. I am sure the first thing you want to know is how do you get text on the screen. The first thing you must do is initialize the LCD by telling your program which pins it will be using to communicate, 99% of the time, this is d4,d5,d6,d7,d8,d9 and this is done by simply adding "LCD INIT d4,d5,d6,d7,d8,d9" to the top of the program. Next we issue the LCD command, the first number tells the Maximite which line to print the text on (1 or 2), the second number tells the Maximite what position in the line to put the text (1 - 16), this is then followed by the text you want displayed. The following program displays "Hello World" followed by the date.
'lcdtxt.bas
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"Hello World"
LCD 2,1, Date$
That is the easy part. The next thing we want to do is make the buttons do something useful. All of the buttons are connected to Pin 35, when in use, Pin 35 will constantly output 3.3 volts, when one of the buttons is pressed, that voltage is reduced and the button can be determined by the voltage. Unfortunately, the voltage differs from board to board, which means you need to determine what these voltages are. The following program configures Pin 35 for Analog Input, this is so we can read the voltage being put out by the pin. The program then starts polling the pin, if no button is pressed and the voltage is 3.3, it does nothing, because no button is being pressed. If the voltage drops, meaning a button is pressed, it prints the voltage on your monitor. Press each button and make a note of the the output for each button.
'bttnvolt.bas
SetPin 35,AIN
Main:
Volt = Pin(35)
If Volt <> 3.3 Then Print Volt
GoTo Main
My results were Left=2.01, Right=0, Up=0.49 and Down=1.26, the numbers actually went out 5 decimal places, but don't worry about that. The Right button is easy, Voltage is 0. Left and Down are both fairly close to 2 and 1 respectively, so by using the Int() function, I can round those values down, without worrying about minor variations in the voltage. Up is a bit more complicated, for this, I need to check to see is the voltage is less than 1 and greater than 0, not tough, but something you have to pay attention to. Putting this altogether, the following program configures Pin 35, initializes the LCD, and displays "LCD Button Test" on the first line. The program then polls Pin 35 for a button press and the displays on the second line which button was pressed. The trailing "*" are there simply to make each string the same length, and no characters are left over from the last button press.
'bttntest.bas
SetPin 35,1
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"LCD Button Test"
Main:
Volt = Pin(35)
If Volt = 0 Then LCD 2,1, "*Right"
If Int(Volt) = 2 Then LCD 2,1, "*Left*"
If Int(Volt) = 1 Then LCD 2,1, "*Down*"
If Volt < 1 And Volt > 0 Then LCD 2,1, "*Up***"
GoTo Main
If you have the LED's from the previous tutorial still connected, you can use the buttons to blink the LED's.
'bblink.bas
SetPin 12, DOUT
SetPin 13, DOUT
SetPin 14, DOUT
SetPin 15, DOUT
SetPin 35, AIN
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"LCD Button Test"
Main:
Volt = Pin(35)
If Volt = 0 Then
LCD 2,1, "*Right"
Pin(15) = 1
Else
Pin(15) = 0
EndIf
If Int(Volt) = 2 Then
LCD 2,1, "*Left*"
Pin(12) = 1
Else
Pin(12) = 0
EndIf
If Int(Volt) = 1 Then
LCD 2,1, "*Down*"
Pin(14) = 1
Else
Pin(14) = 0
EndIf
If Volt < 1 And Volt > 0 Then
LCD 2,1, "*Up***"
Pin(13) = 1
Else
Pin(13) = 0
EndIf
Here are some useful programs for handling the LCD Hat.
'bloff.bas
' This turns the backlight off
SetPin31,DOUT
Pin(31) = 0
'blon.bas
'This turns the backlight on
SetPin31,DOUT
Pin(31) =1
'lcdcls.bas
'This clears all text from the LCD
LCD INIT d4,d5,d6,d7,d8,d9
LCD Clear
When I was making the choice as to what Arduino hat I wanted for my Maximite, it was actually a pretty easy choice. An LCD hat gives you another readable output, which is good for a number of things like error capturing when debugging programs and providing secondary information. These also provide you with a set of buttons that you can use to trigger events. The hat I got can be found here; 16x2 LCD Keypad Shield 1602. These hats are made by many companies, are readily available and are cheap, since you can generally get them for under $10. Make sure if you are buying one of these from a different manufacturer, that is is built on a HD44780 LCD chip, MMBasic has built in support for this chipset.
There are a couple of caveats with these hats, first, there is a reset button, this is handy for resetting your Maximite if, like me, you do not have a power switch. The downside is, if you accidentally press it, you will loose any unsaved programs you have in memory, so be careful and save often. Second, there is a select button, this does not work, it is hooked up to the 5 volt rail, but I have no idea what Pin it is connected to. Lastly, if at first you cannot get anything to display, the contrast is probably set way too low. The contrast is controlled by a screw on top of the blue plastic thing in the upper left corner of the hat. Give the screw 10 complete turns clockwise, and that should make your text become visible and you can adjust to taste from there.
Now, lets get on with doing useful things with this hat. I am sure the first thing you want to know is how do you get text on the screen. The first thing you must do is initialize the LCD by telling your program which pins it will be using to communicate, 99% of the time, this is d4,d5,d6,d7,d8,d9 and this is done by simply adding "LCD INIT d4,d5,d6,d7,d8,d9" to the top of the program. Next we issue the LCD command, the first number tells the Maximite which line to print the text on (1 or 2), the second number tells the Maximite what position in the line to put the text (1 - 16), this is then followed by the text you want displayed. The following program displays "Hello World" followed by the date.
'lcdtxt.bas
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"Hello World"
LCD 2,1, Date$
That is the easy part. The next thing we want to do is make the buttons do something useful. All of the buttons are connected to Pin 35, when in use, Pin 35 will constantly output 3.3 volts, when one of the buttons is pressed, that voltage is reduced and the button can be determined by the voltage. Unfortunately, the voltage differs from board to board, which means you need to determine what these voltages are. The following program configures Pin 35 for Analog Input, this is so we can read the voltage being put out by the pin. The program then starts polling the pin, if no button is pressed and the voltage is 3.3, it does nothing, because no button is being pressed. If the voltage drops, meaning a button is pressed, it prints the voltage on your monitor. Press each button and make a note of the the output for each button.
'bttnvolt.bas
SetPin 35,AIN
Main:
Volt = Pin(35)
If Volt <> 3.3 Then Print Volt
GoTo Main
My results were Left=2.01, Right=0, Up=0.49 and Down=1.26, the numbers actually went out 5 decimal places, but don't worry about that. The Right button is easy, Voltage is 0. Left and Down are both fairly close to 2 and 1 respectively, so by using the Int() function, I can round those values down, without worrying about minor variations in the voltage. Up is a bit more complicated, for this, I need to check to see is the voltage is less than 1 and greater than 0, not tough, but something you have to pay attention to. Putting this altogether, the following program configures Pin 35, initializes the LCD, and displays "LCD Button Test" on the first line. The program then polls Pin 35 for a button press and the displays on the second line which button was pressed. The trailing "*" are there simply to make each string the same length, and no characters are left over from the last button press.
'bttntest.bas
SetPin 35,1
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"LCD Button Test"
Main:
Volt = Pin(35)
If Volt = 0 Then LCD 2,1, "*Right"
If Int(Volt) = 2 Then LCD 2,1, "*Left*"
If Int(Volt) = 1 Then LCD 2,1, "*Down*"
If Volt < 1 And Volt > 0 Then LCD 2,1, "*Up***"
GoTo Main
If you have the LED's from the previous tutorial still connected, you can use the buttons to blink the LED's.
'bblink.bas
SetPin 12, DOUT
SetPin 13, DOUT
SetPin 14, DOUT
SetPin 15, DOUT
SetPin 35, AIN
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"LCD Button Test"
Main:
Volt = Pin(35)
If Volt = 0 Then
LCD 2,1, "*Right"
Pin(15) = 1
Else
Pin(15) = 0
EndIf
If Int(Volt) = 2 Then
LCD 2,1, "*Left*"
Pin(12) = 1
Else
Pin(12) = 0
EndIf
If Int(Volt) = 1 Then
LCD 2,1, "*Down*"
Pin(14) = 1
Else
Pin(14) = 0
EndIf
If Volt < 1 And Volt > 0 Then
LCD 2,1, "*Up***"
Pin(13) = 1
Else
Pin(13) = 0
EndIf
GoTo Main
________________________________________________________
Here are some useful programs for handling the LCD Hat.
'bloff.bas
' This turns the backlight off
SetPin31,DOUT
Pin(31) = 0
'blon.bas
'This turns the backlight on
SetPin31,DOUT
Pin(31) =1
'lcdcls.bas
'This clears all text from the LCD
LCD INIT d4,d5,d6,d7,d8,d9
LCD Clear
The Practical Maximite Part 2
In this tutorial, we are going to add 3 more LED's for a total of 4, then make them blink randomly. For added joy, we will draw matching circles on the screen and depending on how annoying you want to be, we will add sounds to go along with the random blinking. Before I go into the program, you will need to wire up 3 more LED's, if you made it through the last tutorial, it should not be too much of a stretch to wire up these other three. Just remember the Ground needs to connect to the short wire on the LED and the the Data Pins (13,14 and 15) hook up to the long wire on the LED through a resister. Here is mine, the green wires are Ground, the Orange wires are the Data Pins.
Blinking LED's: I went over this in my first tutorial, if you have not worked through that, I suggest you do. We need to configure each Pin for data output, so we can turn the LED's off and on.
Random Numbers: The point of this exercise is to make the 4 LED's blink on and off randomly. We do this by setting the variables G, Y, R and B to either 1 or 2 and we want to assign this randomly. MMBasic has its own random number generator built in, to use it the first thing we must do is seed it off the system clock, this ensures the numbers will be as random as possible. We then use the RND function to generate a random number between 0 and 1, in order to get a number between 0 and 2, we need to multiply the number generated by the RND function by 2, this will generate numbers like .0005432 or 1.0274591, what we want to do is round those numbers to the nearest whole number, being 0 or 1 by using the Int function, then we add 1 to it, so we get a 1 or 2. This is done with the following code; "B = Int(Rnd * 2) + 1". If we wanted to produce a number between 1 and 6 (think 6 sided dice) we would use "Dice = Int(Rnd * 6) + 1".
Circles: When I was originally messing around with my Maximite, I wanted to put matching colored circles on the screen that would flash along with the LED's, that way if something went wrong, I would have some sort of indicator of what might be happening, plus it kind of adds to the show. The circile function is used something like this; "Circle (x pos,y pos), radius, color, aspect, fill/nofill". In the parenthesis is the X and Y positions on the screen, (50,100) would mean the circle is centered 50 pixels from the left and 100 pixels from the top. Radius is exactly that 25 would set the radius of the circle to 25 pixels. The aspect will define the aspect ratio. Because the Maximite's pixels are rectangular an aspect ratio of 0.833 will result in a perfect circle (more or less) on most monitors. Other ratios can be specified for a variety of ovals. If nothing is specified the default is 1.0. So, "Circle (50,100), 25, 2, .833" will produce an empty green circle. Adding an "f" to the end as such; "Circle (50,100), 25, 2, .833, f" will produce a solid green circle.The following shows the numbers assigned for each of the basic 8 colors, 0 is Black.
Sound: This is really just an annoying add on, which I actually did not find use for until later on. But I am putting it here, because, well it is annoying. The Sound function is an easy way to play crude musical notes. The format of the function is fairly simple, "Sound Frequency, Duration". For instance "Sound 440, 250" will play the A note for 250 milliseconds ( one quarter of a second). For this program I am going to use 4 notes and they are as follows; 440 - A, 454 - B, 523 - C and 587 - D. If these are not correct, blame this site, it is where i got these numbers from. I determine the note to play by generating a random number between 1 and 4 with "S = Int(Rnd * 4) + 1", set the S1 variable to the frequency depending on the value of S and then play the note with "Sound S1,250".
Now lets tie this altogether, we start the program with seeding the random number generator, initialize the Data Pin configurations for Data Output and draw out initial circles on the screen.
We then move into the main program, where we randomly determine which LED's will be on and what key we will play and plays it. Then you will see for each of the variables G, Y, R, and B, we check to see if they are a 1 or a 2, using If-Then-EndIf statements. If the variable is set to one, it does not light the LED and draws an empty circle. If the variable is 2, it turns the LED on and draws the corresponding circle filled in. The program then pauses for half a second and goes back to the Main label and starts over again. The program will cycle through this until Ctrl-C is pressed.
' rndblink.bas
Randomize Timer
SetPin 12, DOUT
SetPin 13, DOUT
SetPin 14, DOUT
SetPin 15, DOUT
Circle (50,100), 25, 2, .833, f
Circle (101,100), 25, 6, .833, f
Circle (151,100), 25, 4, .833, f
Circle (201,100), 25, 1, .833, f
Main:
Cls
G = Int(Rnd * 2) + 1
Y = Int(Rnd * 2) + 1
R = Int(Rnd * 2) + 1
B = Int(Rnd * 2) + 1
S = Int(Rnd * 4) + 1
If S = 1 Then S1 = 440
If S = 2 Then S1 = 454
If S = 3 Then S1 = 523
If S = 4 Then S1 = 587
Sound S1,250
If G = 1 Then
G1 = 7
Pin(12) = 0
Circle (50,100), 25, G1, .833
Endif
If G = 2 Then
G1 = 2
Pin(12) = 1
Circle (50,100), 25, G1, .833, f
Endif
If Y = 1 Then
Y1 = 7
Pin(13) = 0
Circle (101,100), 25, Y1, .833
Endif
If Y = 2 Then
Y1 = 6
Pin(13) = 1
Circle (101,100), 25, Y1, .833, f
Endif
If R = 1 Then
R1 = 7
Pin(14) = 0
Circle (151,100), 25, R1, .833
Endif
If R = 2 Then
R1 = 4
Pin(14) = 1
Circle (151,100), 25, R1, .833, f
Endif
If B = 1 Then
B1 = 7
Pin(15) = 0
Circle (201,100), 25, B1, .833
Endif
If B = 2 Then
B1 = 1
Pin(15) = 1
Circle (201,100), 25, B1, .833, f
Endif
Pause 500
GoTo Main
Blinking LED's: I went over this in my first tutorial, if you have not worked through that, I suggest you do. We need to configure each Pin for data output, so we can turn the LED's off and on.
Random Numbers: The point of this exercise is to make the 4 LED's blink on and off randomly. We do this by setting the variables G, Y, R and B to either 1 or 2 and we want to assign this randomly. MMBasic has its own random number generator built in, to use it the first thing we must do is seed it off the system clock, this ensures the numbers will be as random as possible. We then use the RND function to generate a random number between 0 and 1, in order to get a number between 0 and 2, we need to multiply the number generated by the RND function by 2, this will generate numbers like .0005432 or 1.0274591, what we want to do is round those numbers to the nearest whole number, being 0 or 1 by using the Int function, then we add 1 to it, so we get a 1 or 2. This is done with the following code; "B = Int(Rnd * 2) + 1". If we wanted to produce a number between 1 and 6 (think 6 sided dice) we would use "Dice = Int(Rnd * 6) + 1".
Circles: When I was originally messing around with my Maximite, I wanted to put matching colored circles on the screen that would flash along with the LED's, that way if something went wrong, I would have some sort of indicator of what might be happening, plus it kind of adds to the show. The circile function is used something like this; "Circle (x pos,y pos), radius, color, aspect, fill/nofill". In the parenthesis is the X and Y positions on the screen, (50,100) would mean the circle is centered 50 pixels from the left and 100 pixels from the top. Radius is exactly that 25 would set the radius of the circle to 25 pixels. The aspect will define the aspect ratio. Because the Maximite's pixels are rectangular an aspect ratio of 0.833 will result in a perfect circle (more or less) on most monitors. Other ratios can be specified for a variety of ovals. If nothing is specified the default is 1.0. So, "Circle (50,100), 25, 2, .833" will produce an empty green circle. Adding an "f" to the end as such; "Circle (50,100), 25, 2, .833, f" will produce a solid green circle.The following shows the numbers assigned for each of the basic 8 colors, 0 is Black.
Sound: This is really just an annoying add on, which I actually did not find use for until later on. But I am putting it here, because, well it is annoying. The Sound function is an easy way to play crude musical notes. The format of the function is fairly simple, "Sound Frequency, Duration". For instance "Sound 440, 250" will play the A note for 250 milliseconds ( one quarter of a second). For this program I am going to use 4 notes and they are as follows; 440 - A, 454 - B, 523 - C and 587 - D. If these are not correct, blame this site, it is where i got these numbers from. I determine the note to play by generating a random number between 1 and 4 with "S = Int(Rnd * 4) + 1", set the S1 variable to the frequency depending on the value of S and then play the note with "Sound S1,250".
Now lets tie this altogether, we start the program with seeding the random number generator, initialize the Data Pin configurations for Data Output and draw out initial circles on the screen.
We then move into the main program, where we randomly determine which LED's will be on and what key we will play and plays it. Then you will see for each of the variables G, Y, R, and B, we check to see if they are a 1 or a 2, using If-Then-EndIf statements. If the variable is set to one, it does not light the LED and draws an empty circle. If the variable is 2, it turns the LED on and draws the corresponding circle filled in. The program then pauses for half a second and goes back to the Main label and starts over again. The program will cycle through this until Ctrl-C is pressed.
' rndblink.bas
Randomize Timer
SetPin 12, DOUT
SetPin 13, DOUT
SetPin 14, DOUT
SetPin 15, DOUT
Circle (50,100), 25, 2, .833, f
Circle (101,100), 25, 6, .833, f
Circle (151,100), 25, 4, .833, f
Circle (201,100), 25, 1, .833, f
Main:
Cls
G = Int(Rnd * 2) + 1
Y = Int(Rnd * 2) + 1
R = Int(Rnd * 2) + 1
B = Int(Rnd * 2) + 1
S = Int(Rnd * 4) + 1
If S = 1 Then S1 = 440
If S = 2 Then S1 = 454
If S = 3 Then S1 = 523
If S = 4 Then S1 = 587
Sound S1,250
If G = 1 Then
G1 = 7
Pin(12) = 0
Circle (50,100), 25, G1, .833
Endif
If G = 2 Then
G1 = 2
Pin(12) = 1
Circle (50,100), 25, G1, .833, f
Endif
If Y = 1 Then
Y1 = 7
Pin(13) = 0
Circle (101,100), 25, Y1, .833
Endif
If Y = 2 Then
Y1 = 6
Pin(13) = 1
Circle (101,100), 25, Y1, .833, f
Endif
If R = 1 Then
R1 = 7
Pin(14) = 0
Circle (151,100), 25, R1, .833
Endif
If R = 2 Then
R1 = 4
Pin(14) = 1
Circle (151,100), 25, R1, .833, f
Endif
If B = 1 Then
B1 = 7
Pin(15) = 0
Circle (201,100), 25, B1, .833
Endif
If B = 2 Then
B1 = 1
Pin(15) = 1
Circle (201,100), 25, B1, .833, f
Endif
Pause 500
GoTo Main
Thursday, July 9, 2020
The Practical Maximite Part 1
Over the last week or so, I have been experimenting with the Colour Maximite. I have discovered two things as I have been moving along. First, the people at the Backshed forum, where most of the Maximite community hangs out, is not terrible helpful. They are not mean or anything like that, they are just somewhat insular, and are not helpful to newcomers. The second thing I found is there does not seem to be much in the way of useful tutorials. Certainly there are some guides and such, but mostly they are a hodge podge of things mixed together, making it difficult to know where to begin or even to find what you are looking for.
With this in mind, I thought I would create two, maybe three tutorials on what I learned in the last week, starting with how to use the thing with a breadboard, hooking up an LED and making it blink. From there I will work in an LCD panel, and along the way we will draw some circles and play some sounds, maybe even some music. What I am not going to do is go over setting the Maximite up or using the editor, there are plenty of places you can go to learn this. I am also not going to go too deeply into programming in Basic. My goal here is to get you started doing some simple things, so you can get an understanding of how this works at its most basic level.
'blink.bas
SetPin 12,DOUT
Main:
Pin(12) = 1
Pause 500
Pin(12) = 0
Pause 500
GoTo Main
With this in mind, I thought I would create two, maybe three tutorials on what I learned in the last week, starting with how to use the thing with a breadboard, hooking up an LED and making it blink. From there I will work in an LCD panel, and along the way we will draw some circles and play some sounds, maybe even some music. What I am not going to do is go over setting the Maximite up or using the editor, there are plenty of places you can go to learn this. I am also not going to go too deeply into programming in Basic. My goal here is to get you started doing some simple things, so you can get an understanding of how this works at its most basic level.
What you will need is either a Colour Maximite or Color Maximite 2, the Colour Maximite is cheaper, but the Color Maximite 2 is easier to get at this point. You should not spend much more than $100 to $130 for a fully assembled machine. You will also need 1 breadboard, 2 jumper wires, 1 470 Ohm Resister and 1 LED.
The first thing we need to do is wire the LED to the Maximite. Plug one jumper wire into Pin 12 on the back of the Maximite, in my picture, I use a yellow wire. Next plug another wire into Ground (GND) on the back of the Maximite, I used a red wire. Once that is done, we need to plug those wires into the breadboard. In most breadboards, the holes in each horizontal column are a connected set of five, the holes going vertically, are not connected. You will notice a gap in the middle of the board separates the set of five on top and the set of 5 on the bottom, these sets are also not connected. So plug Pin 12 wire into the top left corner hole, then take the resister and plug one side into the one of the holes connected to Pin 12, and plug the other side into top hole just across the gap. Next, plug in the LED so the long wire is in the same horizontal column as the resister. This connects the LED to the resister, which is needed to reduce the voltage, then on to Pin 12. The short wire on the LED should then plug into a hole vertically next to the long wire, then plug GND wire into one of the other holes in the same set of 5 holes as the LED short wire. Your wiring should look similar to mine.
Now we start programming. Start up your Maximite and type edit. We need to start by telling the machine which Pin we are going to use and what we expect to do with it. In this case we want to use Pin 12 and we want to tell it to turn off and on. "SetPin 12,DOUT" is how we do this, when using SetPin the first option is the Pin number, the second is the how we want to configure the Pin. In this case we want Digital Output, here are the other options;
After that we simply loop the main commands Pin(12) and Pause, until Ctrl-c is pressed. Pin(12)=1 turns the LCD on and Pin(12)=0 turns it off. The Pause 500 command simply tells the program to wait for half a second, then continue, by increasing or decreasing this number you can speed up or slow down the blinking.
'blink.bas
Main:
Pin(12) = 1
Pause 500
Pin(12) = 0
Pause 500
GoTo Main
And that is pretty much it for my first tutorial. If it does not work, make sure you have wired it up correctly, specifically that the long wire on the LED is plugged in with the resistor and Pin 12, then check to make sure you typed in the program properly. Also, do not forget to save your program, we will be expanding it in the next tutorial.
Subscribe to:
Posts (Atom)