This is a driver to control the SD20 20 Channel I2C to Servo Driver Chip from www.robot-electronics.co.uk (http://www.robot-electronics.co.uk/htm/sd20tech.htm). This driver will allow a servo channel to be started up, stopped and the duty cycle altered in standard mode. No attempt to include the extended mode is included.
SD20.cpp
- Committer:
- sk398
- Date:
- 2016-01-24
- Revision:
- 0:870a29ad1074
- Child:
- 1:6557cf755742
File content as of revision 0:870a29ad1074:
#include "mbed.h" #include "SD20.h" SD20::SD20(I2C *bus,int I2CAddress, int BusHz) { _bus = bus; deviceAddress = I2CAddress; BusHz = BusHz; _bus -> frequency(BusHz); } int SD20::UpdatePWM(char *DataOutput) { if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN)) { printf("I2C Failed to write\r\n"); return 1; } else { printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput); return 0; } } int SD20::StartStopPWM(int Channel,bool Start) { if(Start == CHANNEL_START) { int DataOutput[] = {Channel,0x01}; if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN)) { printf("I2C Failed to write\r\n"); return 1; } else { printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput); return 0; } } else { int DataOutput[] = {Channel,0x00}; if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN)) { printf("I2C Failed to write\r\n"); return 1; } else { printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput); return 0; } } }