www.huvitera.ee/arduino-mootorid
// NR1.1 - KALLUTUSANDUR JA LED
void setup()
{
pinMode(8,OUTPUT);// set digital pin 8 as “output”
}
void loop()
{
int i;// define variable i
while(1)
{
i=analogRead(5);// read the voltage value of analog pin 5
if(i>512)// if larger that 512(2.5V)
{
digitalWrite(8,LOW);// turn on LED
}
else// otherwise
{
digitalWrite(8,HIGH);// turn off LED
} } }
//////////////////////////////////////////////////////////////////
// NR1 - Servomootor - Kiire asendi vahetamine
#include
int servopin = 9;
int pos = 0;
Servo Servo1;
void setup() {
Servo1.attach(servopin);
}
void loop(){
Servo1.write(0);
delay(1000);
Servo1.write(60);
delay(1000);
}
// NR2 - Servomootor - Sujuv liikumine
void loop() {
for (pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
Servo1.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
Servo1.write(pos);
delay(15);
}
}
//NR 3 - Servomootor - kallutusandur
#include
int servopin = 8;
int pos = 0;
Servo Servo1;
void setup()
{
pinMode(10,OUTPUT);// set digital pin 8 as “output”
Servo1.attach(servopin);
}
void loop()
{
int i;// define variable i
while(1)
{
i=analogRead(5);// read the voltage value of analog pin 5
if(i>512)// if larger that 512(2.5V)
{
digitalWrite(10,LOW);// turn on LED
Servo1.write(90);
delay(15);}
else// otherwise
{
digitalWrite(10,HIGH);// turn off
Servo1.write(0);
delay(15);
}
}
}
//NR 4 - Stepermootor ja nupp
int inpin=7;// initialize pin 7
int val;// define val
#include
#define STEPS 100
Stepper stepper(STEPS, 8, 9, 10, 11);
int previous = 0;
void setup()
{
stepper.setSpeed(100);
pinMode(inpin,INPUT);
}
void loop()
{
val=digitalRead(inpin);
if(val==HIGH) {
stepper.step(1000);
delay(100);
}
else {
delay(100);
}
}
// NR3 - Steppermootor
#include
#define STEPS 100
Stepper stepper(STEPS, 8, 9, 10, 11);
int previous = 0;
void setup()
{
stepper.setSpeed(100);
}
void loop()
{
int val = analogRead(0);
stepper.step(val - previous);
previous = val;
}
// NR5 - Steppermootor - üksikud sammud
#include
const int stepsPerRevolution = 100;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
// step one step:
myStepper.step(1);
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(500);
}