Пример #1
0
/* The "train" requested by servo motors is
 the minimal of 20ms. Our PWM allow us to have
 41.7Hz that means 23.98 ms.
 However the cypress does not offer a good angle
 resolution on this frequency and the user
 has option to operates the servos in 188Hz */
void Servo::prepare_pin(uint8_t pin)
{

	extern TwoWire Wire;

	Wire.begin();

	// let's use this function only to select the bit port
	// the datasheet is a little confusing regading this set

	analogWrite(pin, 1);

	// Select programmable PWM CLK source to 367.7 Hz
	Wire.beginTransmission(CYPRESS_I2C_ADDRESS);
	Wire.write(0x29);
	Wire.write(0x04);
	Wire.endTransmission();

	// Rising edge register
	Wire.beginTransmission(CYPRESS_I2C_ADDRESS);
	Wire.write(0x2a);
	Wire.write(0xff);
	Wire.endTransmission();

	// Set divider to get 47.4Hz freq.
	Wire.beginTransmission(CYPRESS_I2C_ADDRESS);
	Wire.write(0x2C);

	if (this->is188hz)
	Wire.write(0x02);
	else
	Wire.write(0x09);

	Wire.endTransmission();
}
Пример #2
0
void setupTone(int pin) {
  if (!globalToneSetupDone) {   
    Wire.begin();
    globalToneSetupDone = 1;
  }
  
  if (!toneSetupDone[pin]) {
    pinMode(pin, OUTPUT);
    analogWrite(pin, 1);
    toneSetupDone[pin] = 1;
  }  
}
static bool NunchuckInitialize(TwoWire& interface)
{
  interface.begin(); // join i2c bus as master

  interface.beginTransmission(0x52);// transmit to device 0x52
    interface.write((uint8_t)0xF0);// sends a zero.
    interface.write((uint8_t)0x55);// sends a zero.
    interface.write((uint8_t)0xFB);// sends a zero.
    interface.write((uint8_t)0x00);// sends a zero.
  interface.endTransmission();// stop transmitting

  return 1;
}
Пример #4
0
void MCP23018_Init(void)
{
	pinMode(MISC_INT_PIN, INPUT);	// MISC_INT configured as INPUT
	pinMode(MISC_RST_PIN, INPUT);	// MISC_RST configured as INPUT (OUTPUT LOW to RESET)
	pinMode(VEH_IO_INT_PIN, INPUT);
	pinMode(VEH_IO_RST_PIN, INPUT);

	MCP23018_Reset(DEV_MISC);
	MCP23018_Reset(DEV_VEH_IO);

	i2c.begin();

	MCP23018_Init_IOCON();

	// VEH IO INPUT pins (MISC_IN1:MISC_IN8) always inputs
	MCP23018_WRITE(DEV_VEH_IO, (uint8_t)IODIRA, (uint8_t)0xFFu);
}