Part 1: Nintendo DS Touchscreen Color Picker

I figured I’d write-up a tutorial on a little idea I had. I wanted to see if I could make a touchscreen become a color picker. Simple idea and I know it is possible. It was a good introduction into various aspects of building prototypes with an Arduino board. This tutorial is going to be broken up into two parts. First we’ll talk about hooking up an RGB LED to an Arduino board. I’ll be using an Arduino UNO but I’m sure most of the Arduino boards will be very similar. One last thing, keep in mind I am new to embedded development and hardware in general. So these tutorials may not be as descriptive or detailed as one would expect.

Part 1.1 – Putting together the hardware

Arduino LEDSince we’re building a color picker using a touchscreen part we need some way of outputting the results or rather the color that has been chosen. I could have used various types of screens but decided to keep the project simple and went with an RGB LED. I figured if I’m going to be converting an X,Y coordinate to an RGB value that an LED would be enough to show us what color has been chosen.

For this project I used a common anode RGB LED over a common cathode. Why? Well, because it is what I ended up buying and at the time didn’t know there was a difference. You can use either one but it is important to know which one you are using. I’m not too familiar on the gritty details on the differences but some quick searching around the simplest explanation I’ve come to is the flow of electricity. With a common cathode LED you’ll want to ground the common leg which is usually leg 2 the longest leg. With a common anode you want to hook the common leg to 5V pin of the Arduino.

Also keep in mind, lesson I learned from trial and error, is to hook the Red, Green, and Blue legs of the LED into PWM pins of the Arduino. This will allow for a flow of various levels of input over just an on/off set of values. For the purposes of this tutorial, I have decided to use pins 9 (Blue), 10 (Green), and 11 (Red) on the Arduino.

You’ll need 3 resistors for each leg of the color legs on the LED. Most places say you only need a 220-240Ω but at the time all I had was 330Ω resistors. You can use any resistor from 220Ω to 1000Ω though keep in mind the higher the resistance the lower the brightness of the LED.

Following the image on the right, you can see how it all can be laid out. For the purposes of just Part 1 we don’t really need to hook up the ground and 5V as shown on the right side of the image. The red wire connecting the LED’s common leg could be hooked straight into the Arduino’s 5V pin (or if you are using a common cathode then you can just hook it directly into the Arduino’s GND).


To the left is an example picture I took where I have the common leg hooked up directly to the 5V of the Arduino board. If you are uncomfortable with how close these examples are feel free to space it all out a bit. I bunched it all up closely to help keep the rest of my board clean for adding to it in the future. As we’ll see in Part 2 where we’ll start to hook up the Nintendo DS touchscreen.

Part 1.2 – The code

Alright, now that we have the hardware all hooked up properly. We now get to dive into the fun stuff. The coding. Within the Arduino IDE or any IDE that you prefer to use for Arduino development you’ll want to get something up and running quickly.

For starters the code I’ll show you is just an example for the Arduino’s own set of example code. It’ll only use pin 9 (for us that will be the red color). It’ll loop and fade the red color.

One important note about sending values on an Arduino board. The software will use value 0 as full power and 255 as no power.

With the comments this code should be very self-explanatory. We first declare pin 9 to be output so that we can write this pin. Within the loop we send our brightness value with the analogWrite function changing the power to the LED. Since we are starting at 0 we are giving the LED full power on pin 9 from the beginning. With each iteration of the loop our brightness value will increment or decrement by a value of 5 and then we wait 30 milliseconds before looping again. This gives a nice fade out and then fade in of the LED.

From this point you can do whatever you want with the code and play with the LED as you wish. Since I had an RGB LED over a single color LED I decided to take this fading example and build on it. Having the LED fade in and out and switching colors with every fade out. Here is what I came up with for the code.

…and here is a video showing the results off…

In Part 2 of the tutorial we’ll hook up the Nintendo DS Touchscreen and use it to change the color of the RGB LED.

Author: Scyanide

Software Engineer wanting to share his experiences.

1 thought on “Part 1: Nintendo DS Touchscreen Color Picker”

Leave a Reply