Lab_interaccio/2009/Charo/Charo_case2/Charo_case2.pde

83 lines
1.9 KiB
Plaintext
Raw Normal View History

2025-02-25 21:21:58 +01:00
//programacio maquina.definitivo1//prueba delays
int ledPinA = 5;
int ledPinR = 8;
int ledPinV = 9;
unsigned long time=0;
long seg;
int botonPin;
int val;
int servoPin = 3; // Control pin for servo motor
int maxPulse = 1912; // Maximum servo position
int minPulse= -2400; // Minimum servo position
int pulse = 1600; // Amount to pulse the servo
long lastPulse = 0; // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses
void setup(){
Serial.begin(9600);
pinMode(ledPinA, OUTPUT); // sets the digital pin as output
pinMode(ledPinR, OUTPUT);
pinMode(ledPinV, OUTPUT);
pinMode(botonPin, INPUT);
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
}
void loop(){
// pulse the servo again if rhe refresh time (20 ms) have passed:
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delayMicroseconds (refreshTime);
Serial.print (" Pulse:");
Serial.println (pulse);
time=millis();
seg=time/1000;
switch(seg){
case (1/2):
digitalWrite (ledPinV, HIGH);
digitalWrite(ledPinA,HIGH);
digitalWrite(ledPinR,LOW);
break;
//126
case 136:
//digitalWrite (ledPinV, LOW);
digitalWrite(ledPinA,LOW);
digitalWrite (ledPinV, HIGH);
digitalWrite(ledPinR,LOW);
break;
//128
case 138:
pulse=1600;
break;
case 144:
digitalWrite (ledPinV, HIGH);
digitalWrite(ledPinR,LOW);
pulse=919;
break;
//164
case 184:
digitalWrite (ledPinV, HIGH);
digitalWrite(ledPinR,LOW);
pulse=2400;
break;
//196
case 200:
digitalWrite (ledPinV,LOW);
digitalWrite(ledPinR,HIGH);
pulse=1650;
//delay(500);
break;
}
Serial.println(seg);
}