Esempio n. 1
0
int Battery::batteryMv() {
#if defined(__AVR_ATmega32U4__) // Is this a Leonardo board?
  const long INTERNAL_REFERENCE_MV = 2560; // Leo reference is 2.56 volts
#else
  const long INTERNAL_REFERENCE_MV = 1100; // ATmega328 is 1.1 volts
#endif
  const float R1 = 18.0; // Voltage divider values
  const float R2 = 2.2;
  const float DIVISOR = R2 / (R1 + R2);
  
  analogReference(INTERNAL); // Set reference to internal (1.1V)
  analogRead(pin); // Allow the ADC to settle
  delay(10);
  
  int value = 0;
  for (int i=0; i < 8; i++) {
      value = value + analogRead(pin);
  }
  value = value / 8; // Get the average of 8 readings
  int mv = map(value, 0, 1023, 0, INTERNAL_REFERENCE_MV / DIVISOR);
  
  analogReference(DEFAULT); // Set the reference back to default (Vcc)
  analogRead(pin);  // Just to let the ADC settle ready for next reading
  delay(10); // Allow reference to stabilise
  
  return mv;
}
Esempio n. 2
0
 void SCKAmbient::getVcc()
 {
   float temp = base_.average(S3);
   analogReference(INTERNAL);
   delay(100);
   Vcc = (float)(base_.average(S3)/temp)*reference;
   analogReference(DEFAULT);
   delay(100);
 }
Esempio n. 3
0
void LM35Sensor::setHighRes(bool pHighRes) {
  highRes = pHighRes;
  if (highRes) {
    divider = DIVIDER_HIGH_RES;
    analogReference(HIGH_RES);
  } else {
    divider = DIVIDER_LOW_RES;
    analogReference(LOW_RES);
  }
}
/// setARefVoltage:set the ADC reference voltage: (default value: 5V, set to 3 for external reference value, typically 3.3 on Arduino boards)
void AnalogDistanceSensor::setARefVoltage(int refV)
{
  _refVoltage=refV;
  if (_refVoltage == 5)
  {
    analogReference(DEFAULT);
  }
  if (_refVoltage == 3)
  {
    analogReference(EXTERNAL);
  }
}
Esempio n. 5
0
// **************** Setup the Current sensor *********************
void OXS_CURRENT::setupCurrent( ) {
  uint16_t tempRef ; 
  float currentDivider = 1.0 ;
#ifdef USE_INTERNAL_REFERENCE   
  analogReference(INTERNAL) ;
#elif defined(USE_EXTERNAL_REFERENCE)
    analogReference(EXTERNAL) ;
#endif
#if defined(USE_INTERNAL_REFERENCE) && defined(REFERENCE_VOLTAGE) && REFERENCE_VOLTAGE < 2000
  tempRef = REFERENCE_VOLTAGE  ;
#elif defined(USE_INTERNAL_REFERENCE) && defined(REFERENCE_VOLTAGE)
  #error REFERENCE_VOLTAGE must be less than 2000 when USE_INTERNAL_REFERENCE is defined
#elif defined(USE_EXTERNAL_REFERENCE)
#ifndef REFERENCE_VOLTAGE
  #error REFERENCE_VOLTAGE must be defined when USE_EXTERNAL_REFERENCE is defined
#else
  tempRef = REFERENCE_VOLTAGE  ;
#endif
#elif defined(USE_INTERNAL_REFERENCE)
  tempRef = 1100 ;
#elif defined(REFERENCE_VOLTAGE) && REFERENCE_VOLTAGE > 2000
  tempRef = REFERENCE_VOLTAGE  ;
#elif defined(REFERENCE_VOLTAGE)
  #error REFERENCE_VOLTAGE must be greater than 2000 when USE_INTERNAL_REFERENCE is not defined
#else 
  tempRef = 5000 ;
#endif  
#if defined(RESISTOR_TO_GROUND_FOR_CURRENT) && defined(RESISTOR_TO_CURRENT_SENSOR)
  if ( RESISTOR_TO_GROUND_FOR_CURRENT > 0 && RESISTOR_TO_CURRENT_SENSOR > 0) {
    currentDivider = 1.0 * (RESISTOR_TO_GROUND_FOR_CURRENT + RESISTOR_TO_CURRENT_SENSOR ) / RESISTOR_TO_GROUND_FOR_CURRENT ;
  }
#endif 
  offsetCurrentSteps =  1023.0 * MVOLT_AT_ZERO_AMP / tempRef / currentDivider;
  mAmpPerStep =  currentDivider * tempRef / MVOLT_PER_AMP / 1.023 ; 

  currentData.milliAmps.available = false;
  currentData.consumedMilliAmpsAvailable = false;
//  currentData.sumCurrent = 0 ;
  resetValues();
#ifdef DEBUG  
  printer->print("Current sensor on pin:");
  printer->println(_pinCurrent);
  printer->print("Reference voltage:");
  printer->println(tempRef);
  printer->print("Offset for current:");
  printer->println(offsetCurrentSteps);
  printer->print("mAmp per step:");
  printer->println(mAmpPerStep);
  printer->print(" milli=");  
  printer->println(millis());
#endif
  
}
Esempio n. 6
0
void AdcPinShellModule::run(String rawCommand)
{
    // Parse it.
    CommandAndParams cp(rawCommand, serialOut);

    if (!cp.command.equals(F("adc"))) return;
    if (cp.paramCount != 2) return;

    if (cp.params[0].equals(F("aref")))
    {
        serialOut.println(F("Setting A/D converter voltage reference source."));
        if (cp.params[1].equals(F("default")))
        {
            analogReference(DEFAULT);
        }
        else
        if (cp.params[1].equals(F("internal")))
        {
            // analogReference(INTERNAL);
        }
        /*
        else
        if (cp.params[1].equals("1.1v"))
        {
            analogReference(INTERNAL1V1);
        }
        else
        if (cp.params[1].equals("2.56v"))
        {
            analogReference(INTERNAL2V56);
        }
        */
        else
        if (cp.params[1].equals(F("external")))
        {
            analogReference(EXTERNAL);
        }
    }
    else
    if (cp.params[0].equals(F("read")))
    {
        serialOut.println(F("Reading ADC pin value."));

        long int pin = strtol(cp.params[1].c_str(), NULL, 0);
        // serialOut.println(pin);

        if (!(0 <= pin && pin <= 64)) return; // ConfigBlock::MAX_ANALOG_PINS)

        serialOut.println(analogRead(pin));
    }
}
void setAnalogReference() {

	// Setting analog reference to 1.1V will restrict the top measurable temperature to just
	// 43.3°C for LM34 and 60°C for TMP36. This will provide the best temperature resolution
	// and quality of control, though.

	// Setting it to 2.56V will restrict top measurable temperature to 124.4°C for LM34
	// and 206°C for TMP36 - more than enough for casual use.

	analogReference(INTERNAL1V1);

	// http://arduino.cc/it/Reference/AnalogReference says:
	//
	//     After changing the analog reference, the first few readings from analogRead() may not be accurate.
	//
	// To counter this, let's spend some time settling (it appears that first few reads are inaccurate
	// even if the reference voltage hasn't been changed)

	long start = millis();

	do {

		for (int address = A0; address < A0 + 6; address++) {

			analogRead(address);
		}

		// Apparently, 100ms is enough
	} while (millis() - start < 100);
}
Esempio n. 8
0
void hardware::init()
{
    analogReference(EXTERNAL);
    pinMode(BACKLIGHT_PIN, OUTPUT);
    pinMode(OUTPUT_DISABLE_PIN, OUTPUT);
    pinMode(FAN_PIN, OUTPUT);
    pinMode(BUZZER_PIN, OUTPUT);

    pinMode(SMPS_VALUE_PIN, OUTPUT);
    pinMode(SMPS_DISABLE_PIN, OUTPUT);
    pinMode(DISCHARGE_VALUE_PIN, OUTPUT);
    pinMode(DISCHARGE_DISABLE_PIN, OUTPUT);

    pinMode(BALANCER1_LOAD_PIN, OUTPUT);
    pinMode(BALANCER2_LOAD_PIN, OUTPUT);
    pinMode(BALANCER3_LOAD_PIN, OUTPUT);
    pinMode(BALANCER4_LOAD_PIN, OUTPUT);
    pinMode(BALANCER5_LOAD_PIN, OUTPUT);
    pinMode(BALANCER6_LOAD_PIN, OUTPUT);

    pinMode(MUX_ADR0_PIN, OUTPUT);
    pinMode(MUX_ADR1_PIN, OUTPUT);
    pinMode(MUX_ADR2_PIN, OUTPUT);
    pinMode(MUX0_Z_D_PIN, INPUT);
    pinMode(MUX1_Z_D_PIN, INPUT);

    setBatteryOutput(false);
    setFan(false);
    hardware::setBuzzer(0);

    lcd.begin(LCD_COLUMNS, LCD_LINES);
    timer.init();

    Timer1.initialize(TIMER1_PERIOD_MICROSECONDS);         // initialize timer1, and set a 1/2 second period
}
Esempio n. 9
0
Temperature::Temperature(const char *name,
                    int OutputPin_SensorPower, 
                    int InputPin_TemperatureReading, 
                    int TimeBetweenReadings, 
                    float m1, 
                    float m2,
                    float b1,
                    float b2) {
    
    _name                              =   name;
    _OutputPin_SensorPower             =   OutputPin_SensorPower;
    _InputPin_TemperatureReading       =   InputPin_TemperatureReading;
    _TimeBetweenReadings               =   TimeBetweenReadings;
    _m1                                =   m1;
    _m2                                =   m2;
    _b1                                =   b1;
    _b2                                =   b2;

    _temperatureAverage                =   24.0;
    _measuredTemperature               =   24.0;
    _lastTemperatureRead               =   0;
    _VoutAnalogSample                  =   -1;
    _VoutPreviousAnalogSample          =   -1.0;
    _temperatureMeasurementsMarker     =   0;
    _rTemperatureMeasurementsMarker    =   0;
    _measuredTemperatureDeviation      =   0.0;
    _pump                              =   false;

    analogReference(INTERNAL1V1);                   // EXTERNAL && INTERNAL2V56 && INTERNAL1V1
    pinMode(_OutputPin_SensorPower, OUTPUT);        // setup temperature sensor input pin
    digitalWrite(_OutputPin_SensorPower, LOW);      // initialize sensor on
}
//This function uses the known internal reference value of the 328p (~1.1V) to calculate the VCC value which comes from a battery
//This was leveraged from a great tutorial found at https://code.google.com/p/tinkerit/wiki/SecretVoltmeter?pageId=110412607001051797704
float WSNode::fReadVcc()
{
    analogReference(EXTERNAL); //set the ADC reference to AVCC
    burn8Readings(A0); //make 8 readings but don't use them to ensure good reading after ADC reference change
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
    unsigned long start = millis(); //get timer value
    while ( (start + 3) > millis()); //delay for 3 milliseconds
    ADCSRA |= _BV(ADSC); // Start ADC conversion
    while (bit_is_set(ADCSRA,ADSC)); //wait until conversion is complete
    int result = ADCL; //get first half of result
    result |= ADCH<<8; //get rest of the result
    float batVolt = (iREF / result)*1024; //Use the known iRef to calculate battery voltage
    analogReference(INTERNAL); //set the ADC reference back to internal
    burn8Readings(A0); //make 8 readings but don't use them to ensure good reading after ADC reference change
    return batVolt;
}
Esempio n. 11
0
// Bendulum on specified sense and kick pins
Bendulum::Bendulum(byte sPin, byte kPin){
	sensePin = sPin;						// Pin on which we sense the bendulum's passing
	kickPin = kPin;							// Pin on which we kick the bendulum as it passes

	analogReference(EXTERNAL);				// We have an external reference, a 47k+47k voltage divider between 
											//   3.3V and ground
	pinMode(sensePin, INPUT);				// Set sense pin to INPUT since we read from it
	pinMode(kickPin, INPUT);				// Put the kick pin in INPUT (high impedance) mode so that the
											//   induced current doesn't flow to ground

	cycleCounter = 1;						// Current cycle counter for SETTLING and SCALING modes
	tgtSettle = 32;							// Number of cycles to run in SETTLING mode
	tgtScale = 128;							// Number of cycles to run in SCALING mode
	tgtSmoothing = 2048;					// Target smoothing interval in cycles
	curSmoothing = 1;						// Current smoothing interval in cycles
	bias = 0;								// Arduino clock correction in tenths of a second per day
	peakScale = 10;							// Peak scaling value (adjusted during calibration)
	tick = true;							// Whether currently awaiting a tick or a tock
	tickAvg = 0;							// Average period of ticks (μs)
	tockAvg = 0;							// Average period of tocks (μs)
	tickPeriod = 0;							// Length of last tick period (μs)
	tockPeriod = 0;							// Length of last tock period (μs)
	timeBeforeLast = lastTime = 0;			// Clock time (μs) last time through beat() (and time before that)
	runMode = SETTLING;						// Run mode -- SETTLING, SCALING, CALIBRATING, CALFINISH or RUNNING
}
Esempio n. 12
0
int sensors_ext_thermistor()
{
  
  uint8_t i;
  float average;
  
   digitalWrite(EXTERNALTEMPPOWERPIN, HIGH); //Turn the pressure sensor on
   analogReference(DEFAULT);    // Set reference voltage to 5V
   analogRead(EXTERNALTEMPREADPIN);  //trigger sensor to initiate reference voltage change
   delay(100); //allow analogReference to settle
 
  // take N samples in a row, with a slight delay
  int samples[5];
  for (int i=0; i< 5; i++) {
   samples[i] = analogRead(EXTERNALTEMPREADPIN);
   delay(10);
  }
 
  // average all the samples out
  average = 0;
  for (i=0; i< 5; i++) {
     average += samples[i];
  }
  average /= 5;

  // convert the value to resistance
  average = 1023 / average - 1;
  average = SERIESRESISTOR / average;

 float steinhart; //above in one step?
  steinhart = (1/(((log(average/THERMISTORNOMINAL))/BCOEFFICIENT) + (1.0/(TEMPERATURENOMINAL + 273.15))))-273.15;
 
  return steinhart;
} 
Esempio n. 13
0
void hardware::init()
{
    analogReference(EXTERNAL);
    pinMode(OUTPUT_DISABLE_PIN, OUTPUT);

    pinMode(DISCHARGE_VALUE_PIN, OUTPUT);
    pinMode(DISCHARGE_DISABLE_PIN, OUTPUT);

    pinMode(SMPS_VALUE0_PIN, OUTPUT);
    pinMode(SMPS_VALUE1_PIN, OUTPUT);
    pinMode(SMPS_DISABLE_PIN, OUTPUT);

    pinMode(BUZZER_PIN, OUTPUT);

    pinMode(BALANCER1_LOAD_PIN, OUTPUT);
    pinMode(BALANCER2_LOAD_PIN, OUTPUT);
    pinMode(BALANCER3_LOAD_PIN, OUTPUT);
    pinMode(BALANCER4_LOAD_PIN, OUTPUT);
    pinMode(BALANCER5_LOAD_PIN, OUTPUT);
    pinMode(BALANCER6_LOAD_PIN, OUTPUT);

    pinMode(MUX_ADR0_PIN, OUTPUT);
    pinMode(MUX_ADR1_PIN, OUTPUT);
    pinMode(MUX_ADR2_PIN, OUTPUT);
    pinMode(MUX0_Z_D_PIN, INPUT);

    setBatteryOutput(false);
    setFan(false);
    setBuzzer(0);

    lcd.begin(LCD_COLUMNS, LCD_LINES);
    timer.init();

    TimerOne::initialize();
}
Esempio n. 14
0
void init()
{
//	cbi(PORTC, PC0);
//	cbi(PORTC, PC1);
//	PMCR = 0x34;

	CLKPR = 0x80;
	cbi(CLKPR, CLKPCE);

	sbi(MCUCR, JTD);
	sbi(MCUCR, JTD);

	sei();

	TIMER_CS(TCCR0B, 0, TIMER_WITH_EXT_CLK_CS_64);
	TIMER_3BIT_WAVEFORM(0, TIMER_3BIT_WAVEFORM_FPWM);

	sbi(TIMSK0, TOIE0);

	TIMER_CS(TCCR1B, 1, TIMER_WITH_EXT_CLK_CS_64);
	TIMER_4BIT_WAVEFORM(1, TIMER_4BIT_WAVEFROM_PCPWM_8BIT);

	analogReference(REF_AVCC);
	ADC_PRESCALER(ADC_PRECSCALER_DIVISION_128);
	sbi(ADCSRA, ADEN);

}
Esempio n. 15
0
void setup()
{

	Serial.begin(9600);
	Serial.println("Initializing...");
	WiFly.begin(true);
	/*
	while(!SpiSerial.uartConnected())
		SpiSerial.configureUart(9600);
	*/
	Serial.println("Connected to SPI Uart!");

	if(WiFly.createAdHocNetwork("arduino"))
	//if(WiFly.join(ssid, pass, true))
	{

		Serial.print(F("WiFly created AdHoc. Has IP "));
		Serial.println(WiFly.ip());
	}
	else
		Serial.println(F("Failed to create netowrk"));
	analogReference(DEFAULT);
	pinMode(SHT15_DATA_PIN, INPUT);
	pinMode(SHT15_SCK_PIN, OUTPUT);

	pinMode(ANALOG_MIC, INPUT);
	pinMode(ANALOG_LIGHT, INPUT);
	pinMode(ANALOG_SHARP, INPUT);
	/*
if(!WiFly.join("dlink"))
	Serial.println("Could not join network!");
else
	Serial.println(WiFly.ip());
*/
}
Esempio n. 16
0
void setup() {
  pinMode(RED_LED, OUTPUT); //mux the pin for output
  pinMode(GREEN_LED, OUTPUT); //mux the pin for output
  pinMode(PUSH2, INPUT_PULLUP); //mux the pin for intput with debounce enabled
  analogReference(INTERNAL2V5); //set internal reference voltage (set to 2.5V)
  Serial.begin(9600); //start serial interface at 9600 bps
}
Esempio n. 17
0
void hardware::initialize()
{
    analogReference(EXTERNAL);
    pinMode(OUTPUT_DISABLE_PIN, OUTPUT);

    pinMode(DISCHARGE_VALUE_PIN, OUTPUT);
    pinMode(DISCHARGE_DISABLE_PIN, OUTPUT);

    pinMode(BUZZER_PIN, OUTPUT);

    pinMode(SMPS_VALUE_BUCK_PIN, OUTPUT);
    pinMode(SMPS_VALUE_BOOST_PIN, OUTPUT);
    pinMode(SMPS_DISABLE_PIN, OUTPUT);

    setBatteryOutput(false);
    setBuzzer(0);

    lcd.begin(LCD_COLUMNS, LCD_LINES);
    Timer::initialize();
    SMPS::initialize();
    Discharger::initialize();

    TimerOne::initialize();
    adc::initialize();
    AnalogInputs::initialize();
}
Esempio n. 18
0
int sensors_lm60(int powerPin, int readPin)
{
  digitalWrite(powerPin, HIGH);   // Turn the LM60 on
  analogReference(INTERNAL);      // Ref=1.1V. Okay up to 108 degC (424 + 6.25*108 = 1100mV)

   analogRead(readPin);    // More robust reference voltage switch needed since pressure sensor uses 5V, not 1.1
   delay(100);             // Disregard the 1st conversions after changing ref (p.256) and allow reference to settle.

  int adc = analogRead(readPin);  // Real read
  digitalWrite(powerPin, LOW);    // Turn the LM60 off
  int mV = 1100L * adc / 1024L;   // Millivolts
  
  switch (TEMP_UNIT)//Added by: Kyle Crockett
  {
	case 1://C
		return (4L * (mV - 424) / 25)+ CALIBRATION_VAL ;    // Vo(mV) = (6.25*T) + 424 -> T = (Vo - 424) * 100 / 625
	break;
	case 2://K
		return (4L * (mV - 424) / 25) + 273 + CALIBRATION_VAL; //C + 273 = K
	break;
	case 3://F
		return (36L * (mV - 424) / 125) + 32+ CALIBRATION_VAL; // (9/5)C + 32 = F
	break;
  };
  

}
Esempio n. 19
0
float HR202::getHumidity(float t) {
	float a, b, c;
	float tt = t * t;
	a = 112.016090 - 0.360150168 * t + 1.156667e-03 * tt;
	b = -12.725041 - 0.066866381 * t - 1.365699e-04 * tt;
	c = 0.373017 - 0.006363128 * t + 5.289157e-05 * tt;
	float logR;
	analogReference (DEFAULT);
	pinMode(_vcc_pin, OUTPUT);
	digitalWrite(_vcc_pin, HIGH);
	if (_gnd_pin < 255) {
		pinMode(_gnd_pin, OUTPUT);
		digitalWrite(_gnd_pin, LOW);
	}
	int h = analogRead(_adc_pin);
	digitalWrite(_vcc_pin, LOW);
	if (_gnd_pin < 255) {
		digitalWrite(_gnd_pin, HIGH); //reverse current
		analogRead(_adc_pin);
		digitalWrite(_gnd_pin, LOW);
		pinMode(_gnd_pin,INPUT);
	}
	pinMode(_vcc_pin,INPUT);
	logR = log((float) 100 / ((float) 1023 / ((float) h) - 1));
	return a + b * logR + c * logR * logR;

}
/**
 * Initializes the probe
 *
 */
void TemperatureProbe::initialize()
{
	 pinMode( TEMP_PIN, INPUT ); // set LM34 temp sensor pin as an input
	 pinMode( FEEDBACK_PIN, INPUT ); // Ref voltage feedback

	 analogReference(EXTERNAL); // set the analog reference to external

} // end initialize
Esempio n. 21
0
UrineLevel::UrineLevel(int pin, int range, int threshold) {
  
    _pin=pin;
    _range=range;
    _threshold=threshold;
    
    analogReference(DEFAULT);
}
Esempio n. 22
0
/// setARefVoltage(double _refV): Sets the AREF voltage to external, (now only takes 3.3 or 5 as parameter)
/// default is 5 when no AREF is used. When you want to use 3.3 AREF, put a wire between the AREF pin and the
/// 3.3 V VCC pin. This increases accuracy
void AcceleroMMA7361::setARefVoltage(double refV)
{
  _refVoltage = refV;
  if (refV == 3.3)
  {
    analogReference(EXTERNAL);
  }
}
Esempio n. 23
0
/// <summary>
/// setARefVoltage:set the ADC reference voltage: (default value: 5V, set to 3 for 3.3V)
/// </summary>
void DistanceGP2Y0A21YK::setARefVoltage(int refV)
{
	_refVoltage=refV;
	if (_refVoltage==3)
	{
		analogReference(EXTERNAL);
	}
}
Esempio n. 24
0
void InitEQ7() {
  pinMode(EQ7IN_PIN, INPUT);
  pinMode(EQ7STROBE_PIN, OUTPUT);
  pinMode(EQ7RESET_PIN, OUTPUT);
  analogReference(DEFAULT);
  digitalWrite(EQ7RESET_PIN, LOW);
  digitalWrite(EQ7STROBE_PIN, HIGH);
}
Esempio n. 25
0
/// setARefVoltage(int _refV): Sets the AREF voltage to external, (now only takes 3.3 or 5 as parameter)
/// default is 5 when no AREF is used. When you want to use 3.3 AREF, put a wire between the AREF pin and the
/// 3.3 V VCC pin and change the  This increases accuracy
void TemperatureTMP::setARefVoltage(int refV)
{
    _refVoltage = refV;
    if (refV == 3)
    {
        analogReference(EXTERNAL);
    }
}
Esempio n. 26
0
/** Enable ADC. */
void adcBegin(void)
{
    PRR &= ~(1U << PRADC); /* Enable ADC clock. */

    /* Enable ADC, clear interrupt flag and set baud rate to minimum. */
    ADCSRA = (1U << ADEN) | (1U << ADIF) | (0x07U << ADPS0);

    analogReference (INTERNALVCC);
}
//This function sets initial condition of board and gets setting from EEPROM
//this should be called in "setup" Arduino setup function
void WSNode::nodeBegin() {
    analogReference(INTERNAL); //set the ADC reference to internal 1.1V reference
    burn8Readings(A0); //make 8 readings but don't use them to ensure good reading after ADC reference change
    pinMode(7, OUTPUT); //set digital pin 7 as output to control status LED
    pinMode(5,OUTPUT); //set to output, connected to interrupt pin of STTS751 temp sensor
    digitalWrite(5,HIGH); //Need this to pull interrupt pin of STTS751 high (it cannot float)
    getSettings(); //Function used for updating and getting module settings from EEPROM
    setSleepInterval(sInterval);   //Used to set interval between transmits, based on settings data from EEPROM
}
Esempio n. 28
0
void MXS1402::StartSensor()
{
	Wire.begin(); // set up SEABO I2C support
	Wire.beginTransmission(CONTROLCHIPADDRESS); // join I2C
	Wire.write(0x03);
	Wire.write((byte) 0x00);
	Wire.endTransmission(); // leave I2C bus
	Wire.beginTransmission(CONTROLCHIPADDRESS); // join I2C
	Wire.write(0x01);
	Wire.write((byte) 0x80); //enable 5V  disable uart1
	Wire.endTransmission(); // leave I2C bus
#if defined(ADCSRA)
	// set a2d prescale factor to 128
	// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
	// XXX: this will not work properly for other clock speeds, and
	// this code should use F_CPU to determine the prescale factor.
	sbi(ADCSRA, ADPS2);
	sbi(ADCSRA, ADPS1);
	sbi(ADCSRA, ADPS0);

	// enable a2d conversions
	sbi(ADCSRA, ADEN);
#endif

#if	 defined(isant2400cc) || defined(mx231cc)
	pinMode(28, OUTPUT); //A4
	pinMode(13, OUTPUT); //D5
	//pinMode(0, OUTPUT); //B0
	digitalWrite(28,LOW);
	digitalWrite(13,LOW);
	delay(100);
	pinMode(28, INPUT); //A4
	pinMode(13, INPUT); //D5
	pinMode(A2, INPUT);
	analogReference(1); //ref vcc is 3v
#elif defined(isant900cb)
	pinMode(31, INPUT); //PB7
	analogReference(1);
	pinMode(35, INPUT); //PE3


#endif

}
Esempio n. 29
0
SharpIR::SharpIR(int irPin, int avg, int tolerance, int sensorModel) {

    _irPin=irPin;
    _avg=avg;
    _tol=tolerance/100;
    _model=sensorModel;

    analogReference(DEFAULT);
    pinMode(_irPin, INPUT);
}
Esempio n. 30
0
void GeogramONE::configureIO(uint8_t pinNumber, uint8_t eepromAddress)
{
	uint8_t ioConfig = 0;
	ioConfig = EEPROM.read(eepromAddress);
	if(ioConfig == 0){pinMode(pinNumber,INPUT);digitalWrite(pinNumber,LOW);}
	if((ioConfig == 1) || (ioConfig == 5) || (ioConfig == 6)){pinMode(pinNumber,INPUT);digitalWrite(pinNumber,HIGH);}
	if(ioConfig == 2){pinMode(pinNumber,OUTPUT);digitalWrite(pinNumber,LOW);}
	if(ioConfig == 3){pinMode(pinNumber,OUTPUT);digitalWrite(pinNumber,HIGH);}
	if(ioConfig == 4){analogReference(DEFAULT);analogRead(pinNumber - 14);}
}