Assignment 8.1

Post date: Aug 22, 2010 9:28:30 PM

I made a simple 4-key piano that plays a C Major Arpeggio.

Arduino Code:

#include "pitches.h" //includes relevant library

int switch1 = 7 //declares variables

int switch2 = 6

int switch3 = 5

int switch4 = 4

void setup() {

pinMode(switch1, INPUT); //sets pins to inputs

pinMode(switch2, INPUT);

pinMode(switch3, INPUT);

pinMode(switch4, INPUT);

pinMode(switch5, INPUT);


void loop() {

if (digitalRead(switch1) == HIGH) { //if the first switch is pressed,

tone(3, NOTE_C3, 50); //play C3


if (digitalRead(switch2) ==HIGH) { //if the second switch is pressed,

tone(3, NOTE_E3, 50); //play E3


if (digitalRead(switch3) == HIGH) { //if the third switch is pressed,

tone(3, NOTE_G3, 50); //play G3


if (digitalRead(switch4) == HIGH) { //if the fourth switch is pressed,

tone(3, NOTE_C4, 50); //play C4



I downloaded Fritzing, but nothing happens when try to open the file. I see if I can figure it out and post the Fritzing picture later.