Today I begin to learn about the Arduino – the microprocessor, the IDE, the electronics around the processor and the projects, the C based program, etc., and what I realize, again, is that I know so little about so much!
I’m reading Getting Started with Arduino, 2nd Edition, by Massimo Banzi, one of the co-founders of the Arduino. It’s a great book – very accessible. In the book he explains beginning electronics well – something that I know almost nothing about. Something as simple as this, to me, is a revelation:
R (resistance) = V (voltage) / I (current)
V = R * I
I = V / R
_______________
I went on to create my first project and it all went well – I answered some of the questions wandering in my mind and, of course, those made more arise. When I look at the code I feel as if I understand most of it, but not all. It’s that disequilibrium that seems to underlie most of what I do within the tech arena – and I’m not sure I’m functioning with that feeling any better than I ever have…
const int LED = 13; // the pin for the LED
const int BUTTON = 7; // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
int old_val = 0; // this variable stores the previous
// value of “val”
int state = 0; // 0 = LED off while 1 = LED on
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(BUTTON); // read input value and store it
// check if the input is HIGH (button pressed)
// and change the state
if (val == HIGH) {
state = 1 – state;
}
old_val = val; // val is now old, let’s store it
if (state == 1) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW);
}
}
______________
• I’m quite comfortable saying, “I don’t know, let’s find out,” but working alone makes that not so easy – I would far prefer to be working in a small group of active learners – bouncing ideas, new revelations, previous learning reminded – that’s helpful for me. It’s great that there are so many online communities with the resources they provide and that finding an answer to a question, or learning how to ask a question in a better way, is so quickly available, but the human give and take, the purpose behind the task of the moment seems to be lessened without that interaction.
___________________
The second project entailed using Pulse Width Modulation (PWM) – a way to change its brightness by changing the ratio between the on time and the off time of an LED. I got it to work, and have a fairly good idea how the code works, but again, I’m not feeling that comfortable with it. After reading 66 of the 130 pages and doing the projects up to that point I’m starting to feel that familiar feeling of cognitive overload and think that it’s best to stop for the moment.
const int LED = 9; // the pin for the LED
int i = 0; // We’ll use this to count up and down
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT); // tell Arduino LED is an output
}
void loop() {
// put your main code here, to run repeatedly:
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LED, i); // set the LED brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
for (i = 255; i > 0; i–) { // loop from 255 to 1 (fade out)
analogWrite(LED, i); // set the LED brightness
delay(10); // Wait 10ms
}
}
________________