| Home | | Weekly Assignments | | Final Project | | Photo Gallery |

Week 13 - Output device.
This weeks assignment, We need to add an output device into any microcontroller board I made. There are various output devices such as LCD display, speaker, RGB led, servo motor etc. I decided to add a button and an RGB LED to an ATtiny microcontroller and program it in such a way that when I click the button, The LED starts changing its colour.
Designing the board
The board was designed/modified yet again in my favorite sofware Kokopelli.

Added a button and RGB led to the board.

Exported the design as png and used Fab Module to mill the board.

Milled the board using Modella MDX 20

Stuffed the board at electronics workbench. Now the board is ready to be programmed. I used the Arduino software and FabISP to program the board in such a way that the LED will starting changing its coulour based on timer when I click the button on the board.
The code
int redPin = 1;
int greenPin = 10;
int bluePin = 2;
const int buttonPin = 4;
int buttonState = 0; // variable for reading the pushbutton status
int red,blue,green;
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
delay(5000);
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
else if (buttonState == LOW) {
setColor(0, 0, 0);
}
}
void setColor(int red,int green,int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
Final output:
Files:
Files:
djrgb.ino
djoutboard.png djouttraces.png
djoutinterior