Пример #1
0
/*
 *	This method must be called every loop cycle in order to make
 *	the servo on top of which the sensors are located turn left and right.
 *	As in the case of other peripherals, we make the call each loop
 *	instead of waiting for it because we still want that other peripherals
 *	get the CPU as well.. Sharing is caring!
 */
void SensorController::process()
{
	if (_freeMove)
	{
		if (millis() - _startTime > _myServoTurnDelay)
		{
			_startTime = millis();

			if (_myServoPosition > ZERO_POSITION + ROTATION_ANGLE)
			{
				_myServoDirection = -1;
			}
			if (_myServoPosition < ZERO_POSITION - ROTATION_ANGLE)
			{
				_myServoDirection = 1;
			}

			_myServoPosition += _myServoDirection;
			setServoPosition(_myServoPosition);
		}		
	}
	_myServo.write(_myServoPosition);
	getSharpSensor1RawData();
	getSharpSensor2RawData();
	getSharpSensor3RawData();
}
int main() {
    // Handle Ctrl-C quit
    signal(SIGINT, sig_handler);

    // Edison i2c bus is 6
    mraa::I2c *i2c = new mraa::I2c(6);
    assert(i2c != NULL);

    initPWM(i2c);

    while (running) {
        // Alternate two locations with 2-sec delay
        setServoPosition(i2c, 0, 0.2);
        sleep(2.0);
        setServoPosition(i2c, 0, 0.8);
        sleep(2.0);
    }
}
Пример #3
0
// sets the servo to a value given by a message read from the bus
void HardwareControl::setAngle(int angle)
{  
  engageServo(1);
  setServoPosition(angle+calibrationOffset);
  
  /*if(MASTER) {
    Serial.print("next angle: ");
    Serial.print(angle);
    Serial.print("-->");
    Serial.println(servoPosition);
  }*/
}
int main(void) {

	initServoControl();

	//setServoPosition(SERVO_LEFT);	
	//setServoPosition(SERVO_MID);	
	setServoPosition(SERVO_RIGHT);	

	for (;;) {
		_delay_ms(100);
	}

	return 0;
}
void everyMinute(void) {
	minutes++;
	if (minutes > 59) {
		minutes = 0;
		everyHour();
	}
	// If during business hours, set servo to new minute
	// Otherwise, don't need to move moter when laser is off
	if ((hours >= START_TIME) && (hours < STOP_TIME)) {
		setServoPosition();
		enableServo();
		LASER_PORT |= (1 << LASER);		/* make sure laser is on */
	}
	else {
		LASER_PORT &= ~(1 << LASER);	/* make sure laser is off */
	}
}