Social Icons

Jeremy Blum Projects - Arduino Parte [5]

Essa é a semana 5...


Para quem não viu os outros ai vai o link:
Semana [1]
Semana [2]
Semana [3]
Semana [4]











Cada Imagem com Seus respectivos códigos abaixo. Click para dar Zoom.



//Program by Jeremy Blum                                                                                 
//www.jeremyblum.com                                                                                     
//Test Motor Speed Using a                                                                               Transistor                                                                                                         
//Define Pins                                                                     
int motorPin = 9;                                                                     
void setup()
{
  //Set the PWM Motor pin as an output
  pinMode(motorPin, OUTPUT);
}
void loop()
{
  //Increase Motor Speed from 0 -> 255
  for (int i=0; i<=255; i++)
  {
    analogWrite(motorPin, i);
    delay(10);
  }
  delay(500); //Hold it
  //Decrease Motor Speed from 255 -> 0
  for(int i=255; i>=0; i--)
  {
    analogWrite(motorPin, i);
    delay(10);
  }
  delay(500); //Hold it!
}


//Program by Jeremy Blum
//www.jeremyblum.com
//Controls a Servo Motor
//Include Servo Library
#include <Servo.h>
//Define Pins
int servoPin = 9;
//Create Servo Object
Servo jeremysServo;
void setup()
{
  //Attaches the Servo to our object
  jeremysServo.attach(servoPin);
}
void loop()
{
  //We can Turn a Servo to 180 degrees
  for (int i = 0; i <=180; i=i+20)
  {
    jeremysServo.write(i);
    delay(1000);
  }
 
}

---------------------------------------------------

//Program by Jeremy Blum
//www.jeremyblum.com
//Controls a Servo Motor using the info from an IR Distance Sensor
//Include Servo Library
#include <Servo.h>
//Define Pins
int servoPin = 9;
int distPin = 0;
//Create Servo Object
Servo jeremysServo;
void setup()
{
  //Attaches the Servo to our object
  jeremysServo.attach(servoPin);
}
void loop()
{
  //Read the Distance Sensor and adjust values
  int dist = analogRead(distPin);
  int pos = map(dist, 0, 1023, 0, 180);

  //Turn the servo
  jeremysServo.write(pos);
 
}

Nenhum comentário:

Postar um comentário