Interface and Application Programming

1. Assignment:

  • Individual assignment: write an application that interfaces with an input &/or output device that you made;
  • Group assignment: compare as many tool options as possible;

2. Aim

  • Use Arduino to control hardware ;
  • Show the result on Processing application;
  • Use Potentiometer to control the move of servo motor and show the operation on Processing application

3. Prepare

4.Practice

4.1 Arduino hardware connection

I design it inThinkercad,and connect the component according to the following picture.

4.2 Arduino program

#include <Servo.h>
Servo myservo;   //Servomotor library
int potPin = 0; //define the port for Potentiometer

void setup() {
  Serial.begin(9600);
  myservo.attach(9);      //port 9 for servomotor's signal
}

void loop() {
 int val = map(analogRead(potPin),0,1023,0,180);    //Potentiometer's range 0-1024;but processing's range 0-255,so exchange it  
 Serial.println(val); 
  myservo.write(val);

  delay(10);
}

Then update it . In this time check the port again.

4.3 Processing program

import processing.serial.*;
Serial val; 
float w = 0;
void setup() {
size(600, 300); 
val = new Serial(this, "/dev/cu.usbmodem1421", 9600);
val.bufferUntil('\n');
}
void serialEvent(Serial val)
{
w= float(val.readStringUntil('\n'));
}
void draw() {
  background(127);  
  noStroke();   
    fill(255);  
    rect(0, 0, 200, 50); 
    fill(129, 206, 15);  
    rect(0, 0, w,50);    
}

4.4 Test

  • I connect Arduino with my PC;
  • Run the Arduino and Processing.
  • I find the result:When I rotate the Potentiometer, the servo motor will rotate 1/2 degree. In the meantime , the processing show the condition of operation.

5. my final board to run the program.

After test it in arduino, I practice it in my finial board with Processing.

In the hardware connection, I connect as the following:

Then I update Arduino as following I also update the port in Processing

I run the design as the following video

5 Attachment

results matching ""

    No results matching ""