Introduction: LinkIt ONE - Insult Generator
Today's topic: having fun. Yo will learn how to use LCD and button on Mediatek's LinkIt ONE but that will be shadowed by how much fun you will get from algorithmic insult generator!
Let's get started.
Note: idea is not originally mine but I don't know the original source.
Step 1: Hardware
So far as wiring the LCD goes, I would like you to check my other 'ible as I have explained it in depth there - you will also need updated LiquidCrystal libraries available in that 'ible.
The button also has a tiny little trick which could cause you headaches if you haven't worked with buttons and microcontrollers before. but worry not - take a look at diagram above and transfer it to your protoboard circuit.
The resistor should be as big as possible as that will reduce power consumption but you can use anything from 100 Ohm up. That circuit design has to do with how microcontrollers are designed and can not be changed. If you want, you can experiment with connecting the switch alone and seeing what happens (spoiler alert: nothing happens - pin always reads as "HIGH").
Step 2: The Algorithm
The algorithm goes like this:
you have three lists, each containing a specific set of words:
- list: (offensive) nouns
- list: verbs
- list: random nouns
and you combine them as depicted in diagram above - one random word each time. Results should have form of list1 list2 list1 list3 - bastard loving ass waffle for example (note that this is one of most SFW insults from this algorithm).
Note that insults from this program are mostly NSFW. If you want to make it child friendly, you must replace words in all lists with more appropriate alternatives. Keep in mind that if you change length of any of thole lists, you must alter the length variables as well (see next paragraph).
To make this work we need to store all words in separate lists and also store how many words there are in each list. As you will see in code that I did this by storing Strings in list1, list2 and list3 and their lengths in l1, l2 and l3 respectively. That way it was simple to call random word from each list by calling list1[random(l1)] and similarly for other lists
Given the fact my display only had 16 characters/row, I had to print no more than 2 words per line. Luckily my display has two lines but if it didn't I would've had to make text scroll.
If you were to make insults auto rotate (in given time intervals), you would be presented with same insult rotation every time since "random" function takes program up time as seed and that wouldn't change from run to run. By making insult change on button click, a random factor is introduced and insults are different each time.
This sums up the algorithm. All you are left to do is to upload the code and run it.
Have fun and stay tuned for my next 'ible!
We have a be nice policy.
Please be positive and constructive.