mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-01 03:47:23 +03:00
Committing individual examples instead of one .zip
This commit is contained in:
36
build/shared/dist/examples/motors/dc_motor/dc_motor.pde
vendored
Normal file
36
build/shared/dist/examples/motors/dc_motor/dc_motor.pde
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/* DC motor
|
||||
* --------
|
||||
*
|
||||
* Switch a motor on and off making use of a transistor
|
||||
* we use of a BD137 from Fairchild. It is possible to
|
||||
* play with the motor's innertia, and use a potentiometer to
|
||||
* control the speed.
|
||||
*
|
||||
* (cleft) 2005 DojoDave for DojoCorp at Madrid Medialab - Spain
|
||||
*/
|
||||
|
||||
int motorPin = 6; // selec the pin where the motor is connected at
|
||||
int value = 0; // variable to store the reading from the potentiometer
|
||||
int potPin = 0; // analog pin where to plug the potentiometer at
|
||||
|
||||
void setup() {
|
||||
pinMode(motorPin, OUTPUT); // declare the motor as an output
|
||||
beginSerial(9600); // connect to the serial port to send values back
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the potentiometer
|
||||
value = analogRead(potPin);
|
||||
|
||||
// print its value back to the computer
|
||||
printInteger(value);
|
||||
printNewline();
|
||||
|
||||
// turn the motor on
|
||||
digitalWrite(motorPin,HIGH);
|
||||
delay(50);
|
||||
digitalWrite(motorPin,LOW);
|
||||
|
||||
// this will control how long the motor is off
|
||||
delay(value);
|
||||
}
|
121
build/shared/dist/examples/motors/dc_two_motors/dc_two_motors.pde
vendored
Normal file
121
build/shared/dist/examples/motors/dc_two_motors/dc_two_motors.pde
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
/* Driving two DC motors
|
||||
* -----------------------
|
||||
*
|
||||
* Custom timer originally intended to DC motor
|
||||
* control purposes and made from two nested loops:
|
||||
* - "scan cycle" is the main loop
|
||||
* - "control cycle" is the internal loop
|
||||
* Timing id adjusted by changing number of iterations en each loop
|
||||
* and the internal delay of each control cycle iteration (tic). If scan
|
||||
* cycle code takes significative time to jam current control cycle, this
|
||||
* delay could be easily reduced or bypassed.
|
||||
*
|
||||
* (copyleft) 2005 by Quique
|
||||
* <mailto:info@spindesk.com>
|
||||
* posted to the Arduino Forum
|
||||
* <http://www.arduino.cc>
|
||||
*
|
||||
*/
|
||||
|
||||
int ledPin0 = 13; // LED connected to digital pin 13
|
||||
int motorPin1 = 9; // Motor 1 connected to digital pin 9
|
||||
int motorPin2 = 8; // Motor 1 connected to digital pin 8
|
||||
|
||||
int potPin1 = 5; // Potentiometer1 connected to analog pin 5 ( 5 is 1 in some boards)
|
||||
int potPin2 = 4; // Potentiometer1 connected to analog pin 5 ( 4 is 2 in some boards)
|
||||
|
||||
// Timing Setup
|
||||
|
||||
int scanCycle = 10; // Number of control cycles in a scan cycle
|
||||
int controlCycle = 200; // Control cycle iterations
|
||||
int tic = 6; // Control cycle iteration aditional delay in microseconds
|
||||
|
||||
int currentSCycle = 0; // Current scan cycle iteration
|
||||
int currentCCycle = 0; // Current control cycle iteration
|
||||
boolean scanEnable = true; // Allows read analog & digital inputs
|
||||
|
||||
// End timing setup
|
||||
|
||||
int counter = 0; // Scan cycle counter used to change led status
|
||||
int motor1_PW; // motor 1 Pulse Width
|
||||
int motor2_PW; // motor 2 Pulse Width
|
||||
|
||||
/*
|
||||
* Switch the boolean value assigned to any variable
|
||||
*/
|
||||
boolean boolSwitch (boolean *target)
|
||||
{
|
||||
if ( *target ) {*target = false;} else { *target = true; }
|
||||
return *target;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode (ledPin0, OUTPUT); // sets the digital pin as output
|
||||
pinMode (motorPin1, OUTPUT); // sets the digital pin as output
|
||||
pinMode (motorPin2, OUTPUT); // sets the digital pin as output
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Scan cycle
|
||||
|
||||
if (scanEnable)
|
||||
{
|
||||
//
|
||||
// Scan cycle logic here
|
||||
//
|
||||
motor1_PW = analogRead (potPin1)/5; // Pot 1 read scale change
|
||||
motor2_PW = analogRead (potPin2)/5; // Pot 1 read scale change
|
||||
|
||||
// Swith led in pin 13 each 10 scan cycles. We can assume that while
|
||||
// Led is on (or off), porgram has taken 10 scan cycles. So, if we adjust
|
||||
// blink time to 1 sec, we are able to scanning inputs each 100 msec.
|
||||
if (counter++ >= 10)
|
||||
{
|
||||
digitalWrite (ledPin0, boolSwitch (ledPin0)); // Led blink each 10 scan cycles i.e. if
|
||||
// led is on 1 second, we are scaning knobs each
|
||||
// 100 miliseconds
|
||||
counter =0;
|
||||
}
|
||||
}
|
||||
|
||||
// Control cycle
|
||||
for (currentCCycle = 0; currentCCycle < controlCycle; currentCCycle ++)
|
||||
{
|
||||
delayMicroseconds (tic);
|
||||
//
|
||||
// Control cycle logic here
|
||||
//
|
||||
if ( motor1_PW > currentCCycle )
|
||||
{
|
||||
digitalWrite ( motorPin1, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite ( motorPin1, HIGH);
|
||||
}
|
||||
|
||||
if ( motor2_PW > currentCCycle )
|
||||
{
|
||||
digitalWrite ( motorPin2, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite ( motorPin2, HIGH);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Detect completed scan cycle
|
||||
if ( currentSCycle ++ > scanCycle)
|
||||
{
|
||||
scanEnable = true; // Allow readings of external inputs
|
||||
currentSCycle = 0; // Reset scan cycle counter
|
||||
}
|
||||
else
|
||||
{
|
||||
scanEnable = false; //
|
||||
}
|
||||
}
|
||||
|
57
build/shared/dist/examples/motors/stepper_unipolar/stepper_unipolar.pde
vendored
Normal file
57
build/shared/dist/examples/motors/stepper_unipolar/stepper_unipolar.pde
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
/* Stepper Copal Unipolar
|
||||
* ----------------------
|
||||
*
|
||||
* Program to drive a stepper motor coming from a 5'25 disk drive
|
||||
* according to the documentation I found, this stepper: "[...] motor
|
||||
* made by Copal Electronics, with 1.8 degrees per step and 96 ohms
|
||||
* per winding, with center taps brought out to separate leads [...]"
|
||||
* [http://www.cs.uiowa.edu/~jones/step/example.html]
|
||||
*
|
||||
* It is a bipolar stepper motor with 5 wires:
|
||||
*
|
||||
* - red: power connector, I have it at 5V and works fine
|
||||
* - orange and black: coil 1
|
||||
* - brown and yellow: coil 2
|
||||
*
|
||||
* (cleft) 2005 DojoDave for K3
|
||||
* http://www.0j0.org | http://arduino.berlios.de
|
||||
*
|
||||
* @author: David Cuartielles
|
||||
* @date: 20 Oct. 2005
|
||||
*/
|
||||
|
||||
int motorPin1 = 8;
|
||||
int motorPin2 = 9;
|
||||
int motorPin3 = 10;
|
||||
int motorPin4 = 11;
|
||||
int delayTime = 500;
|
||||
|
||||
void setup() {
|
||||
pinMode(motorPin1, OUTPUT);
|
||||
pinMode(motorPin2, OUTPUT);
|
||||
pinMode(motorPin3, OUTPUT);
|
||||
pinMode(motorPin4, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(motorPin1, HIGH);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay(delayTime);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, HIGH);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay(delayTime);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, HIGH);
|
||||
digitalWrite(motorPin4, LOW);
|
||||
delay(delayTime);
|
||||
digitalWrite(motorPin1, LOW);
|
||||
digitalWrite(motorPin2, LOW);
|
||||
digitalWrite(motorPin3, LOW);
|
||||
digitalWrite(motorPin4, HIGH);
|
||||
delay(delayTime);
|
||||
}
|
73
build/shared/dist/examples/motors/stepper_unipolar_advanced/stepper_unipolar_advanced.pde
vendored
Normal file
73
build/shared/dist/examples/motors/stepper_unipolar_advanced/stepper_unipolar_advanced.pde
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/* Stepper Unipolar Advanced
|
||||
* -------------------------
|
||||
*
|
||||
* Program to drive a stepper motor coming from a 5'25 disk drive
|
||||
* according to the documentation I found, this stepper: "[...] motor
|
||||
* made by Copal Electronics, with 1.8 degrees per step and 96 ohms
|
||||
* per winding, with center taps brought out to separate leads [...]"
|
||||
* [http://www.cs.uiowa.edu/~jones/step/example.html]
|
||||
*
|
||||
* It is a bipolar stepper motor with 5 wires:
|
||||
*
|
||||
* - red: power connector, I have it at 5V and works fine
|
||||
* - brown and black: coil 1
|
||||
* - orange and yellow: coil 2
|
||||
*
|
||||
* We use a potentiometer to control the speed and direction of the motor
|
||||
*
|
||||
* (cleft) 2005 DojoDave for K3
|
||||
* http://www.0j0.org | http://arduino.berlios.de
|
||||
*
|
||||
* @author: David Cuartielles
|
||||
* @date: 20 Oct. 2005
|
||||
*/
|
||||
|
||||
int ledPin = 13;
|
||||
int statusLed = LOW;
|
||||
int motorPins[] = {8, 9, 10, 11};
|
||||
int count = 0;
|
||||
int count2 = 0;
|
||||
int delayTime = 500;
|
||||
int val = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT);
|
||||
for (count = 0; count < 4; count++) {
|
||||
pinMode(motorPins[count], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void moveForward() {
|
||||
if ((count2 == 0) || (count2 == 1)) {
|
||||
count2 = 16;
|
||||
}
|
||||
count2>>=1;
|
||||
for (count = 3; count >= 0; count--) {
|
||||
digitalWrite(motorPins[count], count2>>count&0x01);
|
||||
}
|
||||
delay(delayTime);
|
||||
}
|
||||
|
||||
void moveBackward() {
|
||||
if ((count2 == 0) || (count2 == 1)) {
|
||||
count2 = 16;
|
||||
}
|
||||
count2>>=1;
|
||||
for (count = 3; count >= 0; count--) {
|
||||
digitalWrite(motorPins[3 - count], count2>>count&0x01);
|
||||
}
|
||||
delay(delayTime);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(0);
|
||||
if (val > 540) {
|
||||
delayTime = 2048 - 1024 * val / 512 + 1; // move faster the higher the value from the potentiometer
|
||||
moveForward();
|
||||
} else if (val < 480) {
|
||||
delayTime = 1024 * val / 512 + 1; // move faster the lower the value from the potentiometer
|
||||
moveBackward();
|
||||
} else {
|
||||
delayTime = 1024;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user