unsigned int ParkingShield::getAverageBrightness(void)
{
    brightnessValues[brightnessValuesPointer] = analogReadPin(BRIGHTNESS);
    brightnessValuesPointer++;
    brightnessValuesPointer %= BRIGHTNESS_ARRAY_SIZE;
    int average = 0;
    int i;
    for( i = 0; i < BRIGHTNESS_ARRAY_SIZE; ++i)
    {
        average += brightnessValues[i];
    }

    return average / BRIGHTNESS_ARRAY_SIZE;
}
Ejemplo n.º 2
0
void processTWIMessage()
{
  int i;
  if(g_twi_sr_recv_buffer[0] == TWIMSG_HEADER) {
    switch(g_twi_sr_recv_buffer[1]) {
      case TWIMSG_REGACCESS:
        g_current_register = g_twi_sr_recv_buffer[2];
        for(i = 3; i < g_twi_sr_recv_index; i++) {
          *g_current_register = g_twi_sr_recv_buffer[i];
          g_current_register++;
        }
        break;
      case TWIMSG_SET_PIN_MODE:
        setPinMode(g_twi_sr_recv_buffer[2], g_twi_sr_recv_buffer[3]);
        break;
      case TWIMSG_DIGITAL_WRITE_PIN:
        digitalWritePin(g_twi_sr_recv_buffer[2], g_twi_sr_recv_buffer[3]);
        break;
      case TWIMSG_DIGITAL_READ_PIN:
        digitalReadPin(g_twi_sr_recv_buffer[2]);
        break;
      case TWIMSG_ANALOG_WRITE_PIN:
        analogWritePin(g_twi_sr_recv_buffer[2], g_twi_sr_recv_buffer[3]);
        break;
      case TWIMSG_ANALOG_READ_PIN:
        analogReadPin(g_twi_sr_recv_buffer[2]);
        break;
      case TWIMSG_ANALOG_REF:
        analogSetRef(g_twi_sr_recv_buffer[2]);
        break;
    }
  } else {
    /* This message is probably a bluetooth comms message: forward it to the serial */
    /* No need to send zigbee portion of message, start at i=5 */
    if((g_mobotMode == 0) || (g_mobotMode == 1) ) {
      for(i = 5; (i-5) < g_twi_sr_recv_buffer[6] ; i++) {
        g_serialBufferOut[(g_serialBufferOutN + g_serialBufferOutIndex)%SERIAL_BUFFER_SIZE] = 
          g_twi_sr_recv_buffer[i];
        g_serialBufferOutN++;
      }
    } else {
      for(i = 0; i < g_twi_sr_recv_buffer[1] ; i++) {
        g_serialBufferOut[(g_serialBufferOutN + g_serialBufferOutIndex)%SERIAL_BUFFER_SIZE] = 
          g_twi_sr_recv_buffer[i];
        g_serialBufferOutN++;
      }
    }
  }
}
unsigned int ParkingShield::getBrightness(void) const
{
    return analogReadPin(BRIGHTNESS);
}
unsigned int ParkingShield::getTemperature(void) const
{
    unsigned int tempVoltage = analogReadPin(TEMPERATURE);
    return (tempVoltage / 1024.0) * 5.0 * 100.0 - 5.0;
}