Beispiel #1
0
static void PollMotorPower()
{
    uint8_t ii;
    
    // Wow, the following commented code would not work (crashed the board)
    // But, the code after works just fine!!! WTF!!!
    //SensorState.left_motor_voltage = adc_volts(LEFT_MOTOR_VOLTAGE);
    //SensorState.right_motor_voltage = adc_volts(RIGHT_MOTOR_VOLTAGE);
    //SensorState.left_motor_current = adc_volts(LEFT_MOTOR_CURRENT);
    //SensorState.right_motor_current = adc_volts(RIGHT_MOTOR_CURRENT);
    
    adc_init(PROP_A2D_CS, PROP_A2D_SCL, PROP_A2D_DO, PROP_A2D_DI);
    
    for (ii = 0; ii < 4; ++ii)
    {
        float value = adc_volts(ii);
        switch (ii)
        {
            case 0:
                SensorState.left_motor_voltage = value;
                break;
            case 1:
                SensorState.right_motor_voltage = value;
                break;
            case 2:
                SensorState.left_motor_current = value;
                break;
            case 3:
                SensorState.right_motor_current = value;
                break;
        }
    }
}
int main()                                    // Main function
{
  adc_init(21, 20, 19, 18);                   // CS=21, SCL=20, DO=19, DI=18

  float v2, v3;                               // Voltage variables

  while(1)                                    // Loop repeats indefinitely
  {
    v2 = adc_volts(2);                        // Check A/D 2                
    v3 = adc_volts(3);                        // Check A/D 3
    
    putChar(HOME);                            // Cursor -> top-left "home"
    print("A/D2 = %f V%c\n", v2, CLREOL);     // Display volts
    print("A/D3 = %f V%c\n", v3, CLREOL);     // Display volts

    pause(100);                               // Wait 1/10 s
  }  
}
int main()                                          // Main function
{
  pause(1000);                                      // Wait 1 s for Terminal app
  adc_init(21, 20, 19, 18);                         // CS=21, SCL=20, DO=19, DI=18

  float lrV, udV;                                   // Voltage variables

  while(1)                                          // Loop repeats indefinitely
  {
    udV = adc_volts(2);                             // Check A/D 2                
    lrV = adc_volts(3);                             // Check A/D 3
   
    putChar(HOME);                                  // Cursor -> top-left "home"
    print("Up/Down = %.2f V %c\n", udV, CLREOL);    // Display voltage
    print("Left/Right = %.2f V %c\n", lrV, CLREOL); // Display voltage

    pause(100);                                     // Wait 1/10 s
  }  
}
int main()                                    // Main function
{
  pause(1000);                                // Wait 1 s for Terminal app
  adc_init(21, 20, 19, 18);                   // CS=21, SCL=20, DO=19, DI=18

  int i = 0;                                  // Index variable
  while(1)                                    // Loop repeats indefinitely
  {
    if(i == 4)                                // After index = 3
    {
      i = 0;                                  // Reset to zero
      printf("%c", HOME);                     // Cursor home
    }  
    printf("adc[%d] = %d%c\n", i,             // Display raw ADC
            adc_in(i), CLREOL); 
    printf("volts[%d] = %f%c\n\n",            // Display volts
           i, adc_volts(i), CLREOL); 
    i++;                                      // Add 1 to index
    pause(100);                               // Wait 1/10 s
  }  
}