/* Arduino Sketcher Created by Nate Edison 5/14/2015 This is a homemade interface designed to act as a device to draw with an Arduino sketch Processing code */ //set up variables const int LEDred = 6; //display the LED as red to know what color using const int LEDgreen = 5; //display the LED as green to know what color using const int LEDblue = 4; //display the LED as blue to know what color using const int resetButton = 3; //reset the canvas const int blueButton = 2; //change the color to blue const int greenButton = 8; //change the color to green const int redButton = 7;//change the color to red byte xVal = 0; byte yVal = 255; void setup() { //set up our outputs pinMode(LEDred, OUTPUT); pinMode(LEDgreen, OUTPUT); pinMode(LEDblue, OUTPUT); //set up our inputs pinMode(resetButton, INPUT); pinMode(blueButton, INPUT); pinMode(greenButton, INPUT); pinMode(redButton, INPUT); Serial.begin(9600); //sets up the code so it can //use serial comuniaciton } void loop() { //Set up variables for our drawing controls int knob = analogRead(A0); int softPot = analogRead(A1); //Serial.println("Knob reads:"); //Serial.println(knob); int knobOutput = map(knob, 0, 1023, 0, 255); int softPotOutput = map(softPot, 0, 1023, 0, 255); //analogWrite(blue, blueLight); //Serial.println("mapping:"); //Serial.println(blueLight); //delay(1000); //These were used in accordance with a single blue LED //to find where values ranged over the analog sensors. int blueButtonState = digitalRead(blueButton); // sets up the variable to read the output of the blue button if (blueButtonState == HIGH) { colorBlue(); //calls the function to make the color blue } int greenButtonState = digitalRead(greenButton); //sets up the variable to read the output of the green button if (greenButtonState == HIGH) { colorGreen(); //calls the function to make the color green } int redButtonState = digitalRead(redButton); //sets up the variable to read the output of the red button if (redButtonState == HIGH) { colorRed(); // calls the function to make the color red } if ((redButtonState == HIGH) && (blueButtonState == HIGH)) { colorMagenta(); //calls the function to make the color magenta } if ((redButtonState == HIGH) && (greenButtonState == HIGH)) { colorYellow(); } if ((blueButtonState == HIGH) && (greenButtonState == HIGH)) { colorCyan(); } int resetButtonState = digitalRead(resetButton); //sets up the variable to read teh output of the reset button if (resetButtonState == HIGH) { reset(); //calls the function to reset the drawing } if ((knobOutput >= 0) && (knobOutput <= 70)) { moveleft(); //calls the function to move the line to the left } if ((knobOutput >= 131) && (knobOutput <= 255)) { moveright(); // calls the function to move the line right } if ((softPotOutput >= 4) && (softPotOutput <= 116)) { moveup(); //calls the function to move the line up. } if ((softPotOutput >= 124) && (softPotOutput <= 255)) { movedown(); // calls the function to move the line down } } void colorBlue() { //turns the LED and the color of drawing blue digitalWrite(LEDgreen, LOW); digitalWrite(LEDred, LOW); digitalWrite(LEDblue, HIGH); Serial.write('c'); Serial.write(0); Serial.write(0); Serial.write(255); } void colorGreen() { //turns the LED and the color of drawing green digitalWrite(LEDblue, LOW); digitalWrite(LEDred, LOW); digitalWrite(LEDgreen, HIGH); Serial.write('c'); Serial.write(0); Serial.write(255); Serial.write(0); } void colorRed() { //turns the LED and the color of drawing red digitalWrite(LEDblue, LOW); digitalWrite(LEDgreen, LOW); digitalWrite(LEDred, HIGH); Serial.write('c'); Serial.write(255); Serial.write(0); Serial.write(0); } void colorMagenta() { //turns the LED and the color of drawing magenta digitalWrite(LEDblue, HIGH); digitalWrite(LEDred, HIGH); digitalWrite(LEDgreen, LOW); Serial.write('c'); Serial.write(255); Serial.write(0); Serial.write(255); } void colorYellow() { //turns the LED and the color of drawing yellow digitalWrite(LEDblue, LOW); digitalWrite(LEDgreen, HIGH); digitalWrite(LEDred, HIGH); Serial.write('c'); Serial.write(255); Serial.write(255); Serial.write(0); } void colorCyan() { //turns the LED and the color of drawing cyan digitalWrite (LEDblue, HIGH); digitalWrite(LEDgreen, HIGH); digitalWrite(LEDred, LOW); Serial.write('c'); Serial.write(0); Serial.write(255); Serial.write(255); } void reset() { // resets the canvas Serial.write('r'); xVal = 0; yVal = 255; } void moveleft() { //moves the line left Serial.write('d'); xVal = xVal -= 1; Serial.write(xVal); Serial.write(yVal); delay(100); } void moveright() { // moves the line right Serial.write('d'); xVal = xVal += 1; Serial.write(xVal); Serial.write(yVal); delay(100); } void moveup() { // moves the line up Serial.write('d'); Serial.write(xVal); yVal = yVal -= 1; Serial.write(yVal); delay(100); } void movedown() { //moves the line down Serial.write('d'); Serial.write(xVal); yVal = yVal += 1; Serial.write (yVal); delay(100); }