private void setAccelFullScaleRange(AccelFullScale afs) { // * 0 = +/- 2g // * 1 = +/- 4g // * 2 = +/- 8g // * 3 = +/- 16g // bit 4 len 2 this.WriteBits(Register.ACCEL_CONFIG, 4, 2, Convert.ToByte(afs)); Hardware.Library.Delay(10); }
private static float get_aRes(AccelFullScale ascale) { switch (ascale) { // Possible accelerometer scales (and their register bit settings) are: // 2 Gs (00), 4 Gs (01), 8 Gs (10), and 16 Gs (11). // Here's a bit of an algorith to calculate DPS/(ADC tick) based on that 2-bit value: case AccelFullScale.AFS_2G: return(2.0f / 32768.0f); case AccelFullScale.AFS_4G: return(4.0f / 32768.0f); case AccelFullScale.AFS_8G: return(8.0f / 32768.0f); case AccelFullScale.AFS_16G: return(16.0f / 32768.0f); default: throw new Exception("get_aRes error"); } }