Arduino
Arduino
From last lecture, we had an initial understanding about the Arduino. And today we will go
on this content, you will: understand the Arduino workflow and programming syntax. Then,
study the Photoresistor in Arduino and how it works with Processing code. And finally,
appreciate how to design a system with Arduino.
Then, the compiler converts it into machine code. Machine code is a low-level programming
language consisting of 1 and 0.
Next, it goes through "bootloading." that allows new sketches to be uploaded via the USB
port.
It is stored in flash memory and then, the microcontroller executes the instructions in the
machine, resulting in LED blink. Clear?
Here's a brief introduction of Arduino syntax. Since it is similar to the other programming
languages which you learned before, we just take a quick review.
• Arduino programming has five common data types. Each type has different range of
values and memory requirements.
• And there are four common types of operators in Arduino. Assignment, Arithmetic,
Comparison, and Logical.
Next, we are going to the photoresistor. A photoresistor is a simple component that changes
its resistance based on the ambient light. We can use it to create interactive projects, such as
controlling the particles with various parameters, such as the color, size, and the rotation
speed to create an immersive experience.
We begin by declaring two variables: "pwm" and "PinMode". "pwm" represents the LED
signal to control the brightness, and "PinMode" represents the digital pin on the Arduino
board.
Next, we add a delay, and add the 'pwm' variable to increase in loop.
Finally, we have an if statement that checks whether the current value has exceeded 200.
Well, in processing code, Let's look at the "draw" function. If the data is available, we read it
with myPort.read(). And store in the variable "val".
Next, we set the background color to black. This will ensure the particles against a dark
background.
Then, we translate the origin to the center of the screen and make sure the particles are around
the center.
Next, we add a rotation around the y and x-axis, which is based on the frame rate and "val"
variable.
Finally, we display particles on the screen with shape. By changing of the rotation parameters,
we can create different effects in our project.
Now let’s move on to the final part, before we start to design an interactive project, there are
several design principles which should be considered.
One principle to follow is simplicity. The code should be kept simple and easy to understand.
For example, if you are designing an LED controller, you could use simple functions like
'turnOn', 'turnOff', and 'setColor' to control, instead of complex logic.
Another principle is modularity. This means that the code should be divided into independent
modules that can be easily understood and tested. For example, if you are designing a
Bluetooth application, you could separate the code into modules for communication, control,
and data readings. It makes us easier to test and debug, and also makes the code more
readable.
A third principle is abstraction. This means hiding the details of the code, and just exposing
the key functionalities to the user. For example, if you are designing a temperature sensing
system, it is better to only offer user an interface to read the temperature value for simple
interaction.
Lastly, the principle of efficiency should be considered. This means making the code run
faster and reduce resources.
By following these principles, I hope you guys could create your own design successfully.
And next seminar, we will further talk about your own project. Well, that’s all of today’s
lesson. Have a nice day!