This last week in the Robotics and Mechatronics course continued with the PWM work from last week. Although the work for this wasn’t very complex, there are parts of the pulse system which seem like they could be very useful in various systems.
The new content for the week was a series of systems on an Arduino, all of which were simple, however some of them I haven’t used in the C language yet. The first part of this was the ‘Switch Cases’. I have used the idea of a switch case before, however I haven’t yet seen it visualised in such a way as this. This system had a potentiometer, which essentially had its values mapped between 0 and 4, which each were used for something different. However this system didn’t use the .map() method and instead used a switch() method with different cases within it. This seems like it does the same thing, but in a much more straightforward way, although I am not sure whether or not it is actually more efficient for the Arduino unit.
The second part of this document was creating functions. This was easier than the first as I have done it many times before both in C and in Python. I last used a function in C for my robot dog project. The function was used to control the looping of the leg movement, something that should’ve been done with the previously mentioned PWM in hindsight.
The next section of this weeks work was arrays. This is the part I found most interesting. This is because even though I have seen and used arrays before, I haven’t seen them used as they were in this Arduino system. I have used arrays essentially to do what a list does, and mainly used those in Python. But here, they were used to store data as a list, then go through the array and activate each item consecutively. Although the idea itself seems very basic, seeing this done the way it was showed me how efficient the code can be,
This simple system of 6 LEDs (one of which doesn’t work) uses arrays to turn all the LEDs on and off one after the other. Although there probably isn’t a lot of use for turning LEDs on and off in a cycle like this, the program could be used in parallel with others to make something cool. My first idea upon seeing this was to add some kind of either speaker of microphone to be paired with this, and turn them on based on volume. This idea doesn’t necessarily need to be done with arrays or a series of LEDs, where it could be paired with simply analog pins to change the brightness, it may make a clearer representation of the noise produced.
This simple logic of creating an array, in this case for the pin values, and then iterating over them in a loop doing the same thing to each one quickly in succession is a very basic yet very useful way of working with a large quantity of the same thing, and something I am definitely going to keep in mind for the next time I encounter this type of situation.
The final section of this document is bit maths – mathematical operations carried out by individual bits. I haven’t yet done this section of the document, but I have used bitwise operation before in a python task so I haven’t fallen far behind. Looking at the document, the operations look rather basic, being and/or/xor/not logic gates, and shift left/right functions.
Other than this document, the NCSS challenge on Grok has opened up. I started this on the first day it opened, however it took me a few attempts for a couple sections as I can’t remember how to efficiently code in Python. But after trying different approaches to nearly every challenge, I have successfully completed week 1 of the advanced and intermediate NCSS challenge.