NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


#include <Servo.h>

Servo servo1;



// variables to hold the pushbutton states

// Define the analog input pin to measure flex sensor position:

const int flexpin = 0;


void setup()
{
// Use the serial monitor window to help debug our sketch:

Serial.begin(9600);

// Enable control of a servo on pin 9:

servo1.attach(9);


// Set up the LED pin to be an output:

}


void loop()
{
static int position;
int flexposition; // Input value from the analog pin.
int servoposition; // Output value to the servo.

// Read the position of the flex sensor (0 to 1023):

flexposition = analogRead(flexpin);

// Because the voltage divider circuit only returns a portion
// of the 0-1023 range of analogRead(), we'll map() that range
// to the servo's range of 0 to 180 degrees. The flex sensors
// we use are usually in the 600-900 range:

servoposition = map(flexposition, 700, 980, 0, 180);
servoposition = constrain(servoposition, 0, 180);

// Now we'll command the servo to move to that position:

servo1.write(servoposition);

// Because every flex sensor has a slightly different resistance,
// the 600-900 range may not exactly cover the flex sensor's
// output. To help tune our program, we'll use the serial port to
// print out our values to the serial monitor window:

Serial.print("sensor: ");
Serial.print(flexposition);
Serial.print(" servo: ");
Serial.println(servoposition);
delay(150);

// Note that all of the above lines are "print" except for the
// last line which is "println". This puts everything on the
// same line, then sends a final carriage return to move to
// the next line.

// After you upload the sketch, turn on the serial monitor
// (the magnifying-glass icon to the right of the icon bar).
// You'll be able to see the sensor values. Bend the flex sensor
// and note its minimum and maximum values. If you replace the
// 600 and 900 in the map() function above, you'll exactly match
// the flex sensor's range with the servo's range.







for (position = 0; position <= 180; position += 1)
{
servo1.write(position++); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}

/* for(position = 180; position >= 0; position -= 1)
{
servo1.write(position); // Move to next position
delay(20); // Short pause to allow it to move

}*/



}


     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.