Objective:
In this week's assignment we had to Write an application that interfaces a user with an input and/or output device that I made
I am going to be using my Final Project board which is the one that i made in the Output devices week, with a simple servo motor as an output, and my application will be moving the servo motor on 3 different positions using Processing. Processing is a sketchbook software, allows us to code using visual context.
I went through these tutorials Youtube and Sparkfun to learn how to use it, we connect the processing interface with the Arduino IDE to be able to control the inputs and outputs with a graphic User Interface.
To start using Processing with At328p, I have to install a library that enables processing to work with microcontrollers. So I installed processing, and then installed controlP5 library by going to sketches>>import library>>add library. .
After that it's time to start with the code, first I included the Controlp5 Library and started making my Window.
Then I added the buttons which will move the servo motor.
After that I added the serial Functions "port.write()" which will send serial signal to my board, and upon recieving the signals my board will execute different commands.
#include <servo.h>
// Include the Servo library
// Declare the Servo pin
int servoPin = 3;
// Create a servo object
Servo Servo1;
void setup() {
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
Serial.begin(19200);
}
void loop(){
if(Serial.available()){
char val = Serial.read();
if(val =='a'){
// Make servo go to 0 degrees
Servo1.write(0);
}
if(val =='b'){
// Make servo go to 90 degrees
Servo1.write(90);
}
if(val =='c'){
// Make servo go to 180 degrees
Servo1.write(180);
}
}
}