Arduino Hello World
I recently was gifted a new Arduino UNO R3 in a kit with some other compatible sensors and stuff. I wanted be able to program it from my Lenovo Chromebook using VS Code and only be installing minimal software (given the limited space and computing power of the Chromebook)

Starting Components
- The kit, with
- an Arduino UNO R3
- a breadboard and leads
- various resistors (includingh 220 ohm)
- an RGB LED
- a USB A to USB B cable
- Lenovo Chromebook
- USB C (plug) to USB A (socket)
Installing Software
I basically followed this guide which is likely to be more up-to-date and correct than mine
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
I didn't install it into the bin folder so I linked to it
sudo ln ./bin/arduino-cli /usr/bin
Then I installed the core for the board I have
arduino-cli core install arduino:avr
Enabling the USB device
I had to go to the terminal settings and enable the Arduino USB device
VSCode Tasks (all optional)
I'm using tasks to make the various Arduino cli commands convenient
Creating the tasks
I made the file .vscode/tasks.json with a command to build and one to upload
{
"version": "2.0.0",
"tasks": [
{
"label": "Arduino Compile",
"type": "shell",
"command": "arduino-cli compile --fqbn arduino:avr:uno ${fileDirname}",
"group": {
"reveal": "always",
"kind": "build",
"isDefault": true
}
},
{
"label": "Arduino Upload",
"type": "shell",
"command":"arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno ${fileDirname}"
}
]
}
Running them in vanilla VSCode
- ctrl + shift + b to compile
- ctrl + shift + p to open the menu >
Tasks: run task>Arduino: upload
Using an extension to run tasks (optional)
To make it easier, I installed the extension Tasks by actboy168, so now the tasks can be executed from the status bar of VSCode
My first program
I created the following uno.ino which flashes the built-in LED (on for 800ms, off for 200ms) in a loop. Using the tasks I set up, i compiled then uploaded the code.
void setup(){
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
digitalWrite(LED_BUILTIN, HIGH);
delay(800);
digitalWrite(LED_BUILTIN, LOW);
delay(200);
}
Okay, that worked fine. Let's bust out the breadboard and an RGB LED
RGB cycle program
This project uses the digital pins 9, 10 and 11, and the function "analogWrite" which outputs a PWM signal with varying "on" time, which has the effect of controlling the brightness
This plot shows how the r, g, and b variables changes as hue progresses through the range 0 to 360.

I found that lowering the brightness of my LED means that its not so blidingly bright, but you can manage this with resistors too.
My circuit looks like this (for me the red, green and blue LEDs are part of an RGB LED):

// Set up constants
const int PIN_RED = 9;
const int PIN_GREEN = 10;
const int PIN_BLUE = 11;
const float BRIGHTNESS = 0.2;
const float MULTIPLIER = 255.0 / 120.0 * BRIGHTNESS;
int hue = 0;
void setup(){
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_BLUE, OUTPUT);
}
void loop(){
const int r = 120 - min(120, min(abs(hue), abs(hue - 360)));
const int g = 120 - min(120, abs(hue - 120));
const int b = 120 - min(120, abs(hue - 240));
// Normalise the total brightness to a range from 0-255, then dim it a bit
analogWrite(PIN_RED, (int)(r * MULTIPLIER));
analogWrite(PIN_GREEN, (int)(g * MULTIPLIER));
analogWrite(PIN_BLUE, (int)(b * MULTIPLIER));
// Delay by 24ms, then increment hue (resetting at 260)
delay(24);
hue = (hue + 1) % 360;
}