Esempio n. 1
0
void Smarty::setButtonPin(uint8_t pin) {
	m_buttonPin = pin;
	pinMode(pin, INPUT_PULLUP);
}
Esempio n. 2
0
void *toneHandler(void *arg)
{
  tone_thread_param *param;
  param = (tone_thread_param*)arg;

  int tPin = param->tonePin;
  pinMode(tPin, OUTPUT_FAST);
  long delayAmount;
  long loopTime;
  unsigned long time1;
  unsigned long time2;
  int currentThreadControlID = param->threadID; //when threadControl[tPin] is modified by another thread it will no longer be equal to currentThreadControlID which exits the loop below allowing it to die

  if((param->frequency) > 0)
  {
    delayAmount = (long)(1000000/(param->frequency))/2 - 1;
    loopTime = (long)((param->duration*1000)/(delayAmount*2));

    if((param->duration) > 0)
    {
      //implementing this way because delayMicroseconds is blocking which makes the generated tone not accurate enough
      for (int x=0;x<loopTime;x++)
      {
        if(currentThreadControlID != threadControl[tPin])
        {
          break;
        }
        time1 = micros();
        time2 = time1;
        fastDigitalWrite(tPin,HIGH);
        while(((long)(time2 - time1)) <= delayAmount)
        {
          time2 = micros();
        }
        time1 = micros();
        fastDigitalWrite(tPin,LOW);
        while(((long)(time2 - time1)) <= delayAmount)
        {
          time2 = micros();
        }
      }
    }
    else
    {
      //infinite loop
      while(true)
      {
        if(currentThreadControlID != threadControl[tPin])
        {
          break;
        }
        time1 = micros();
        time2 = time1;
        fastDigitalWrite(tPin,HIGH);
        while(((long)(time2 - time1)) <= delayAmount)
        {
          time2 = micros();
        }
        time1 = micros();
        fastDigitalWrite(tPin,LOW);
        while(((long)(time2 - time1)) <= delayAmount)
        {
          time2 = micros();
        }
      }
    }
  }
  else
  {
    time1 = micros();
    time2 = time1;
    delayAmount = (param->duration)*1000;
    while(((long)(time2 - time1)) <= delayAmount)
    {
      time2 = micros();
      if(currentThreadControlID != threadControl[tPin])
      {
        break;
      }
    }
  }
}
Esempio n. 3
0
void decodeurDCF1_c::begin(uint8_t pin)
{
  _pin = pin & 127;
  pinMode(_pin, INPUT);
}
Esempio n. 4
0
void A110x2500Gdo0Init()
{
    pinMode (RF_GDO0, INPUT);
}
Esempio n. 5
0
/* Constructor. */
Thermistor::Thermistor(int pin, TemperatureUnits units)
{
  m_Pin = pin;
  pinMode(m_Pin, INPUT);
  m_Units = units;
}
Esempio n. 6
0
//*****Sender Class Begins*****
Sender::Sender (short pinIn, Protocol * protIn){
	pin = pinIn;
	prot = protIn;
	pinMode(pin,OUTPUT);
}
Esempio n. 7
0
boolean Plugin_006(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;
  
  switch(function)
    {
    #ifdef PLUGIN_006_CORE
  
    
    case PLUGIN_COMMAND:
      {
      DHT_Pin=PIN_WIRED_OUT_1+event->Par1-1;
      byte dht_dat[5];
      byte dht_in;
      byte i;
      byte Retry=0;

      UserVariablePayload(event->Par2,  0x0011); // Temperature
      UserVariablePayload(event->Par2+1,0x00d1); // Relative humidity %

      do
        {  
        pinMode(DHT_Pin,OUTPUT);                                                // DHT start condition, pull-down i/o pin for 18ms
        digitalWrite(DHT_Pin,LOW);                                              // Pull low
        delay(18);
        digitalWrite(DHT_Pin,HIGH);                                             // Pull high
        delayMicroseconds(40);
        pinMode(DHT_Pin,INPUT);                                                 // change pin to input
        delayMicroseconds(40);
        dht_in = digitalRead(DHT_Pin);

        if(!dht_in)
          {
          delayMicroseconds(80);
          dht_in = digitalRead(DHT_Pin);

          if(dht_in)
            {
            delayMicroseconds(40);                                              // now ready for data reception
            for (i=0; i<5; i++)
              dht_dat[i] = read_dht_dat();
              
            byte dht_check_sum = dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];   // check checksum. Checksum calculation is a Rollover Checksum by design.

            if(dht_dat[4]== dht_check_sum)
              {

              #if PLUGIN_006_CORE==11                                           // Code door de DHT-11 variant
              TempFloat=float(dht_dat[2]);                                      // Temperatuur
              UserVariableSet(event->Par2  ,TempFloat,DHT_EVENT);
              TempFloat=float(dht_dat[0]);                                      // Vochtigheid
              UserVariableSet(event->Par2+1,TempFloat,DHT_EVENT);
              #endif
              
              
              #if PLUGIN_006_CORE==22 || PLUGIN_006_CORE==33                    // Code door de DHT-22 of DHT-33 variant
              if (dht_dat[2] & 0x80)                                            // negative temperature
                {
                TempFloat=-0.1 * word(dht_dat[2] & 0x7F, dht_dat[3]);
                UserVariableSet(event->Par2,TempFloat,DHT_EVENT);
                }
              else
                {
                TempFloat=0.1 * word(dht_dat[2], dht_dat[3]);
                UserVariableSet(event->Par2,TempFloat,DHT_EVENT);
                }
              TempFloat=word(dht_dat[0], dht_dat[1]) * 0.1;                     // vochtigheid
              UserVariableSet(event->Par2+1,TempFloat,DHT_EVENT);
              #endif

              success=true;
              }
            }
          }
        if(!success)
          delay(1000);

        }while(!success && ++Retry<3);        
      break;
      }
    #endif // CORE
    
    #if NODO_MEGA
    case PLUGIN_MMI_IN:
      {
      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);
  
      if(GetArgv(string,TempStr,1))
        {
        if(strcasecmp(TempStr,PLUGIN_NAME)==0)
          {
          if(event->Par1>0 && event->Par1<HARDWARE_WIRED_OUT_PORTS && event->Par2>0 && event->Par2<=USER_VARIABLES_MAX_NR-1)
            {
            event->Type = NODO_TYPE_PLUGIN_COMMAND;
            event->Command = PLUGIN_ID;                                         // Plugin nummer  
            success=true;
            }
          }
        }
      free(TempStr);
      break;
      }
  
    case PLUGIN_MMI_OUT:
      {
      strcpy(string,PLUGIN_NAME);                                               // Eerste argument=het commando deel
      strcat(string," ");
      strcat(string,int2str(event->Par1));
      strcat(string,",");
      strcat(string,int2str(event->Par2));
      break;
      }
    #endif // MMI
    }      
  return success;
  }
Esempio n. 8
0
/*****************************************************************************************************************************
*
*  Send command to Servo to make turn it an turn back
*
*   Returns: 
*     - RESULT_IS_OK
*
*****************************************************************************************************************************/
int8_t servoTurn(const uint8_t _servoPin, const uint16_t _targetPulseWidth, const uint32_t _turnTime, const uint32_t _holdTime = 0, const uint16_t _returnPulseWidth = 0)
{
  uint32_t startHolding, idleTime, turnTime;
  uint8_t servoPinPort, servoPinBit;
  volatile uint8_t *servoOutRegister;
  int8_t rc = RESULT_IS_FAIL;

  servoPinBit  = digitalPinToBitMask(_servoPin);
  servoPinPort = digitalPinToPort(_servoPin);

  if (NOT_A_PIN == servoPinPort) {
    goto finish;
  }
  servoOutRegister = portOutputRegister(servoPinPort);

  pinMode(_servoPin, OUTPUT);

  stopTimerOne(); 

  if (_targetPulseWidth) {
    // if target angle (thru _targetPulseWidth) is specified - servo must get pulses every PULSE_INTERVAL (usually 20) ms 
    //     for _turnTime and _holdTime to stay on position
    //
    // Work cycle = pulse_width_in_uS + (20 ms - pulse_width_in_ms)
    idleTime = SERVO_PULSE_INTERVAL - (_targetPulseWidth / 1000UL);
    turnTime = _turnTime + _holdTime;

    startHolding = millis();
    // Send pulse to turn the servo and hold it on position
    do {
      // Turn to the "target" angle
      //  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
      *servoOutRegister |= servoPinBit;
      delayMicroseconds(_targetPulseWidth);
      *servoOutRegister &= ~servoPinBit;
      //   }
      // delay() is used because delayMicroseconds take no more that 16000 uS
      delay(idleTime);
    } while (turnTime > millis() - startHolding);
  }

  if (_returnPulseWidth) {
    // if return angle (thru _returnPulseWidth) is specified - servo must get pulses every PULSE_INTERVAL (usually 20) ms 
    //     for _turnTime
    //
    idleTime = SERVO_PULSE_INTERVAL - (_returnPulseWidth / 1000UL);

    startHolding = millis();
    do {
      // Turn to the "return" angle
      //  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
      *servoOutRegister |= servoPinBit;
      delayMicroseconds(_returnPulseWidth);
      *servoOutRegister &= ~servoPinBit;
      //   }
      // delay() is used because delayMicroseconds take no more that 16000 uS
      delay(idleTime);
    } while (_turnTime > millis() - startHolding);
  }

  startTimerOne(); 
  rc = RESULT_IS_OK;

finish:
  gatherSystemMetrics(); 
  return rc;
}
Esempio n. 9
0
/**
 * Enable transmissions
 *
 * @param nTransmitterPin    Arduino Pin to which the sender is connected to
 */
void RCSwitch::enableTransmit(int nTransmitterPin) {
  this->nTransmitterPin = nTransmitterPin;
  pinMode(this->nTransmitterPin, OUTPUT);
}
Esempio n. 10
0
void Platform::Init()
{ 
  byte i;

  compatibility = me;

  line->Init();
  messageIndent = 0;

  //network->Init();

  massStorage->Init();

  for(i=0; i < MAX_FILES; i++)
    files[i]->Init();

  fileStructureInitialised = true;

  mcp.begin();

  sysDir = SYS_DIR;
  configFile = CONFIG_FILE;

  ipAddress = IP_ADDRESS;
  netMask = NET_MASK;
  gateWay = GATE_WAY;

  // DRIVES

  stepPins = STEP_PINS;
  directionPins = DIRECTION_PINS;
  enablePins = ENABLE_PINS;
  disableDrives = DISABLE_DRIVES;
  lowStopPins = LOW_STOP_PINS;
  highStopPins = HIGH_STOP_PINS;
  maxFeedrates = MAX_FEEDRATES;
  accelerations = ACCELERATIONS;
  driveStepsPerUnit = DRIVE_STEPS_PER_UNIT;
  instantDvs = INSTANT_DVS;
  potWipes = POT_WIPES;
  senseResistor = SENSE_RESISTOR;
  maxStepperDigipotVoltage = MAX_STEPPER_DIGIPOT_VOLTAGE;
  zProbePin = -1; // Default is to use the switch
  zProbeCount = 0;
  zProbeSum = 0;
  zProbeValue = 0;
  zProbeADValue = Z_PROBE_AD_VALUE;
  zProbeStopHeight = Z_PROBE_STOP_HEIGHT;

  // AXES

  axisLengths = AXIS_LENGTHS;
  homeFeedrates = HOME_FEEDRATES;
  headOffsets = HEAD_OFFSETS;

  // HEATERS - Bed is assumed to be the first

  tempSensePins = TEMP_SENSE_PINS;
  heatOnPins = HEAT_ON_PINS;
  thermistorBetas = THERMISTOR_BETAS;
  thermistorSeriesRs = THERMISTOR_SERIES_RS;
  thermistorInfRs = THERMISTOR_25_RS;
  usePID = USE_PID;
  pidKis = PID_KIS;
  pidKds = PID_KDS;
  pidKps = PID_KPS;
  fullPidBand = FULL_PID_BAND;
  pidMin = PID_MIN;
  pidMax = PID_MAX;
  dMix = D_MIX;
  heatSampleTime = HEAT_SAMPLE_TIME;
  standbyTemperatures = STANDBY_TEMPERATURES;
  activeTemperatures = ACTIVE_TEMPERATURES;
  coolingFanPin = COOLING_FAN_PIN;
  turnHeatOn = HEAT_ON;

  webDir = WEB_DIR;
  gcodeDir = GCODE_DIR;
  tempDir = TEMP_DIR;

  for(i = 0; i < DRIVES; i++)
  {

	  if(stepPins[i] >= 0)
	  {
		  if(i > Z_AXIS)
			  pinModeNonDue(stepPins[i], OUTPUT);
		  else
			  pinMode(stepPins[i], OUTPUT);
	  }
	  if(directionPins[i] >= 0)
	  {
		  if(i > Z_AXIS)
			  pinModeNonDue(directionPins[i], OUTPUT);
		  else
			  pinMode(directionPins[i], OUTPUT);
	  }
	  if(enablePins[i] >= 0)
	  {
		  if(i >= Z_AXIS)
			  pinModeNonDue(enablePins[i], OUTPUT);
		  else
			  pinMode(enablePins[i], OUTPUT);
	  }
	  Disable(i);
	  driveEnabled[i] = false;
  }

  for(i = 0; i < AXES; i++)
  {
	  if(lowStopPins[i] >= 0)
	  {
		  pinMode(lowStopPins[i], INPUT);
		  digitalWrite(lowStopPins[i], HIGH); // Turn on pullup
	  }
	  if(highStopPins[i] >= 0)
	  {
		  pinMode(highStopPins[i], INPUT);
		  digitalWrite(highStopPins[i], HIGH); // Turn on pullup
	  }
  }  
  
  if(heatOnPins[0] >= 0)
        pinMode(heatOnPins[0], OUTPUT);
  thermistorInfRs[0] = ( thermistorInfRs[0]*exp(-thermistorBetas[0]/(25.0 - ABS_ZERO)) );
  
  for(i = 1; i < HEATERS; i++)
  {
    if(heatOnPins[i] >= 0)
      pinModeNonDue(heatOnPins[i], OUTPUT);
    thermistorInfRs[i] = ( thermistorInfRs[i]*exp(-thermistorBetas[i]/(25.0 - ABS_ZERO)) );
  }

  if(zProbePin >= 0)
	  pinMode(zProbePin, INPUT);
  
  if(coolingFanPin >= 0)
  {
	  pinMode(coolingFanPin, OUTPUT);
	  analogWrite(coolingFanPin, 0);
  }

  InitialiseInterrupts();
  
  addToTime = 0.0;
  lastTimeCall = 0;
  lastTime = Time();
  longWait = lastTime;
  
  active = true;
}
Esempio n. 11
0
void AnalogSwitch::Init(){
	if (AnalogPin >= 0 && AnalogPin <= 5)
		pinMode(AnalogPin, INPUT); //receive switch signal
}
Esempio n. 12
0
void MeteoTemp::doStep3()
{
	int i, j = 0, counter = 0;
	uint8_t laststate = HIGH;
	data[0] = data[1] = data[2] = data[3] = data[4] = 0;

#ifdef DEBUG
	unsigned long begin = micros();
#endif
	noInterrupts();
	digitalWrite(_pin, HIGH);
	delayMicroseconds(40);
	pinMode(_pin, INPUT);

	// read in timings
	for ( i=0; i< MAXTIMINGS; i++) {
		counter = 0;
		while (digitalRead(_pin) == laststate) {
			counter++;
			delayMicroseconds(1);
			if (counter == 255) {
				break;
			}
		}
		laststate = digitalRead(_pin);

		if (counter == 255) break;

		// ignore first 3 transitions
		if ((i >= 4) && (i%2 == 0)) {
			// shove each bit into the storage bytes
			data[j/8] <<= 1;
			if (counter > _count)
				data[j/8] |= 1;
			j++;
		}

	}

	interrupts();

	bool isOk = (j >= 40) &&
			(data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF));
	hasData = isOk;
	if (isOk) {
		mainLogic.temperatureUpdated();
	}
	status.needUpdate();
#ifdef DEBUG
	unsigned long duration = micros() - begin;
	Serial.print(F("DHT="));
	Serial.print(isOk);
	Serial.print(F(" took:"));
	Serial.println(duration);

	Serial.print(lastTemperature());
	Serial.print(F("° "));
	Serial.print(lastHumidity());
	Serial.println(F("%"));
#endif
	prepareStep1(false);
}
Esempio n. 13
0
void MeteoTemp::doStep2()
{
	pinMode(_pin, OUTPUT);
	digitalWrite(_pin, LOW);
	prepareStep3();
}
Esempio n. 14
0
void LED::setup() 
{  
  pinMode(outPin, OUTPUT);
}
Esempio n. 15
0
void Ultrasonic::init(){
	pinMode(tPin, OUTPUT);
	digitalWrite(tPin, 0);
	pinMode(ePin, INPUT);
}
Esempio n. 16
0
//
// Exported functions
//
void gps_setup() {
#ifdef GPS_ON_PIN
  pinMode(GPS_ON_PIN, OUTPUT);
  digitalWrite(GPS_ON_PIN,HIGH);
#endif  
}
Esempio n. 17
0
// enable/disable blinking of pin 13 on IR processing
void IRrecv::blink13(int blinkflag)
{
  irparams.blinkflag = blinkflag;
  if (blinkflag)
    pinMode(BLINKLED, OUTPUT);
}
Esempio n. 18
0
IRsendBase::IRsendBase () {
 pinMode(TIMER_PWM_PIN, OUTPUT);  
 digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low    
}
Esempio n. 19
0
/*
  This initialization is called by the Arduino framework.
 */
void setup() {
  pinMode(LED_BUILTIN,     OUTPUT);
  pinMode(LED_RGB_RED,     OUTPUT);
  pinMode(LED_RGB_GREEN,   OUTPUT);
  pinMode(LED_RGB_BLUE,    OUTPUT);
  pinMode(SR_CLOCK,        OUTPUT);
  pinMode(SR_LATCH,        OUTPUT);
  pinMode(SR_SERIAL,       OUTPUT);
  pinMode(US_DIST_TRIG,    OUTPUT);
  pinMode(PASSIVE_BUZZLER, OUTPUT);

  pinMode(US_DIST_ECHO,    INPUT);
  pinMode(LIGHT_SENSORS,   INPUT);
  pinMode(HUMAN_DETECTOR,  INPUT);
  pinMode(THERMOMETER,     INPUT);
  pinMode(JOYSTICK_X,      INPUT);
  pinMode(JOYSTICK_Y,      INPUT);
  pinMode(JOYSTICK_BUTTON, INPUT_PULLUP);

  // Reset all virtual pins
  vpFlush();

  // Activate serial port with the given boud rate
  Serial.begin(9600);

  custom_setup(); // Application specific initialization
}
Esempio n. 20
0
void IRrecvBase::enableIRIn(void) { 
  pinMode(irparams.recvpin, INPUT);
  resume();
}
Esempio n. 21
0
void analogWrite(uint32_t ulPin, uint32_t ulValue) {

  if (ulValue == 0)
  {
    digitalWrite(ulPin, LOW);
    return;
  }

  if (ulValue == 255)
  {
    digitalWrite(ulPin, HIGH);
    return;
  }

	if (Timer1_Compare_Unit_Occupied_by_Pin[0] == ulPin)
	{
		update_PWM_value(ulPin, ulValue, 0);
	}
	else if (Timer1_Compare_Unit_Occupied_by_Pin[1] == ulPin)
	{
		update_PWM_value(ulPin, ulValue, 1);
	}
	else if (Timer1_Compare_Unit_Occupied_by_Pin[2] == ulPin)
	{
		update_PWM_value(ulPin, ulValue, 2);
	}
	else if (Timer2_Compare_Unit_Occupied_by_Pin[0] == ulPin)
	{
		update_PWM_value(ulPin, ulValue, 3);
	}
	else
	{
		if ((Timer1_Compare_Unit_Occupied_by_Pin[0] == 255) && (Timer1_Compare_Unit_Occupied_by_Pin[1] == 255) && (Timer1_Compare_Unit_Occupied_by_Pin[2] == 255))
		{
			// Timer1 is not used: need to initialize it

			// Configure ulPin as output
      digitalWrite(ulPin, LOW);
			pinMode(ulPin, OUTPUT);

			if (ulValue > 0)
			{
				// Configure GPIOTE channel "gpiote_channel" to toggle the PWM pin state
				// Note that we can only connect one GPIOTE task to an output pin
				nrf_gpiote_task_config(0, ulPin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
			}
			GPIOTE_Channels_Occupied[ulPin] = 0;

			NRF_TIMER1->TASKS_STOP = 1;
			NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
			//NRF_TIMER1->PRESCALER = 6; // Source clock frequency is divided by 2^6 = 64
			NRF_TIMER1->PRESCALER = 0; // Source clock frequency is divided by 2^6 = 64 /////////////////////////////////////////
			//NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_08Bit;
			NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit;	////////////////////////////
			// Clears the timer, sets it to 0
			NRF_TIMER1->TASKS_CLEAR = 1;
			NRF_TIMER1->CC[0] = (2^PWM_RESOLUTION - 1);
			NRF_TIMER1->CC[1] = (2^PWM_RESOLUTION - 1);
			NRF_TIMER1->CC[2] = (2^PWM_RESOLUTION - 1);
			NRF_TIMER1->CC[3] = 0;
			NRF_TIMER1->EVENTS_COMPARE[0] = 0;
			NRF_TIMER1->EVENTS_COMPARE[1] = 0;
			NRF_TIMER1->EVENTS_COMPARE[2] = 0;
			NRF_TIMER1->EVENTS_COMPARE[3] = 0;
			// Interrupt setup
			NRF_TIMER1->INTENSET = (TIMER_INTENSET_COMPARE3_Enabled << TIMER_INTENSET_COMPARE3_Pos);
      attachInterrupt(TIMER1_IRQn, TIMER1_Interrupt);

			// Start clock
			NRF_TIMER1->TASKS_START = 1;

			turn_On_PPI_to_GPIO_for_PWM(ulPin, 0, NRF_TIMER1, 0);

			PWM_Channels_Value[0] = (2^PWM_RESOLUTION - 1) - mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
			Timer1_Compare_Unit_Occupied_by_Pin[0] = ulPin;
			Pin_Occupied_for_PWM[ulPin] = 1;
		}
		else
		{
			if (Timer1_Compare_Unit_Occupied_by_Pin[0] == 255)
			{
				// Configure ulPin as output
        digitalWrite(ulPin, LOW);
				pinMode(ulPin, OUTPUT);
				if (ulValue > 0)
				{
					// Configure GPIOTE channel "gpiote_channel" to toggle the PWM pin state
					// Note that we can only connect one GPIOTE task to an output pin
					nrf_gpiote_task_config(0, ulPin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
				}
				GPIOTE_Channels_Occupied[ulPin] = 0;
				turn_On_PPI_to_GPIO_for_PWM(ulPin, 0, NRF_TIMER1, 0);
				PWM_Channels_Value[0] = (2^PWM_RESOLUTION - 1) - mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
				Timer1_Compare_Unit_Occupied_by_Pin[0] = ulPin;
				Pin_Occupied_for_PWM[ulPin] = 1;
				NRF_TIMER1->EVENTS_COMPARE[0] = 0;
			}
			else if (Timer1_Compare_Unit_Occupied_by_Pin[1] == 255)
			{
				// Configure ulPin as output
        digitalWrite(ulPin, LOW);
				pinMode(ulPin, OUTPUT);
				if (ulValue > 0)
				{
					// Configure GPIOTE channel "gpiote_channel" to toggle the PWM pin state
					// Note that we can only connect one GPIOTE task to an output pin
					nrf_gpiote_task_config(1, ulPin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
				}
				GPIOTE_Channels_Occupied[ulPin] = 1;
				turn_On_PPI_to_GPIO_for_PWM(ulPin, 1, NRF_TIMER1, 1);
				PWM_Channels_Value[1] = (2^PWM_RESOLUTION - 1) - mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
				Timer1_Compare_Unit_Occupied_by_Pin[1] = ulPin;
				Pin_Occupied_for_PWM[ulPin] = 1;
				NRF_TIMER1->EVENTS_COMPARE[1] = 0;
			}
			else if (Timer1_Compare_Unit_Occupied_by_Pin[2] == 255)
			{
				// Configure ulPin as output
        digitalWrite(ulPin, LOW);
				pinMode(ulPin, OUTPUT);
				if (ulValue > 0)
				{
					// Configure GPIOTE channel "gpiote_channel" to toggle the PWM pin state
					// Note that we can only connect one GPIOTE task to an output pin
					nrf_gpiote_task_config(2, ulPin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
				}
				GPIOTE_Channels_Occupied[ulPin] = 2;
				turn_On_PPI_to_GPIO_for_PWM(ulPin, 2, NRF_TIMER1, 2);
				PWM_Channels_Value[2] = (2^PWM_RESOLUTION - 1) - mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
				Timer1_Compare_Unit_Occupied_by_Pin[2] = ulPin;
				Pin_Occupied_for_PWM[ulPin] = 1;
				NRF_TIMER1->EVENTS_COMPARE[2] = 0;
			}
			else
			{
				// All channels of Timer1 is occupied, need to use Timer2
				// FIXME
//				if (!RFduinoGZLL_used && Timer2_Compare_Unit_Occupied_by_Pin[0] == 255)
				if (Timer2_Compare_Unit_Occupied_by_Pin[0] == 255)
				{
					// Timer2 is not used: need to initialize it

					// Configure ulPin as output
          digitalWrite(ulPin, LOW);
					pinMode(ulPin, OUTPUT);

					if (ulValue > 0)
					{
						// Configure GPIOTE channel "gpiote_channel" to toggle the PWM pin state
						// Note that we can only connect one GPIOTE task to an output pin
						nrf_gpiote_task_config(3, ulPin, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
					}
					GPIOTE_Channels_Occupied[ulPin] = 3;

					NRF_TIMER2->TASKS_STOP = 1;
					NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;
					//NRF_TIMER2->PRESCALER = 6; // Source clock frequency is divided by 2^6 = 64
					NRF_TIMER2->PRESCALER = 0; // Source clock frequency is divided by 2^6 = 64 /////////////////////////////////////////
					//NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_08Bit;
					NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;	////////////////////////////
					// Clears the timer, sets it to 0
					NRF_TIMER2->TASKS_CLEAR = 1;
					NRF_TIMER2->CC[0] = (2^PWM_RESOLUTION - 1);
					NRF_TIMER2->CC[3] = 0;
					NRF_TIMER2->EVENTS_COMPARE[0] = 0;
					NRF_TIMER2->EVENTS_COMPARE[3] = 0;

					// Interrupt setup
					NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE3_Enabled << TIMER_INTENSET_COMPARE3_Pos);
          attachInterrupt(TIMER2_IRQn, TIMER2_Interrupt);

					// Start clock
					NRF_TIMER2->TASKS_START = 1;

					turn_On_PPI_to_GPIO_for_PWM(ulPin, 3, NRF_TIMER2, 0);

					PWM_Channels_Value[3] = (2^PWM_RESOLUTION - 1) - mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
					Timer2_Compare_Unit_Occupied_by_Pin[0] = ulPin;
					Pin_Occupied_for_PWM[ulPin] = 1;
				}
				else
				{
					// Using all 4 TASK channels of GPIOTE, it is not possible to add another PWM channel.
				}
			}
		}
	}

/*
	// Defaults to digital write
	pinMode(ulPin, OUTPUT);
	ulValue = mapResolution(ulValue, _writeResolution, 8);
	if (ulValue < 128)
		digitalWrite(ulPin, LOW);
	else
		digitalWrite(ulPin, HIGH);
*/
}
Esempio n. 22
0
/* If your hardware is set up to do both output and input but your particular sketch
 * doesn't do any output, this method will ensure that your output pin is low
 * and doesn't turn on your IR LED or any output circuit.
 */
void IRrecvBase::No_Output (void) {
 pinMode(TIMER_PWM_PIN, OUTPUT);  
 digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low    
}
void Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) {
 /*
	if (isHardwareSPI()) {
    // Setup hardware SPI.
    SPI.begin();
    SPI.setClockDivider(PCD8544_SPI_CLOCK_DIV);
    SPI.setDataMode(SPI_MODE0);
    SPI.setBitOrder(MSBFIRST);
  }
  else {
*/
    // Setup software SPI.

    // Set software SPI specific pin outputs.
    pinMode(_din, OUTPUT);
    pinMode(_sclk, OUTPUT);

    // Set software SPI ports and masks.
    clkport     = portOutputRegister(digitalPinToPort(_sclk));
    clkpinmask  = digitalPinToBitMask(_sclk);
    mosiport    = portOutputRegister(digitalPinToPort(_din));
    mosipinmask = digitalPinToBitMask(_din);
//  }

  // Set common pin outputs.
  pinMode(_dc, OUTPUT);
  if (_rst > 0)
      pinMode(_rst, OUTPUT);
  if (_cs > 0)
      pinMode(_cs, OUTPUT);

  // toggle RST low to reset
  if (_rst > 0) {
    digitalWrite(_rst, LOW);
    delay(500);
    digitalWrite(_rst, HIGH);
  }

  // get into the EXTENDED mode!
  command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );

  // LCD bias select (4 is optimal?)
  command(PCD8544_SETBIAS | bias);

  // set VOP
  if (contrast > 0x4f)
    contrast = 0x4f;

  command( PCD8544_SETVOP | contrast); // Experimentally determined


  // normal mode
  command(PCD8544_FUNCTIONSET);

  // Set display to Normal
  command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);

  // initial display line
  // set page address
  // set column address
  // write display data

  // set up a bounding box for screen updates

  updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
  // Push out pcd8544_buffer to the Display (will show the AFI logo)
  display();
}
Esempio n. 24
0
// enable/disable blinking of pin 13 on IR processing
void IRrecvBase::blink13(bool blinkflag)
{
  irparams.blinkflag = blinkflag;
  if (blinkflag)
     pinMode(BLINKLED, OUTPUT);
}
Esempio n. 25
0
void nRF905_init()
{
#ifdef ARDUINO
	pinMode(TRX_EN, OUTPUT);
	pinMode(PWR_MODE, OUTPUT);
	pinMode(TX_EN, OUTPUT);

#if NRF905_COLLISION_AVOID
	pinMode(CD, INPUT);
#endif

#if AM_IS_USED_HW
	pinMode(AM, INPUT);
#endif

#if !NRF905_DR_SW
	pinMode(DR, INPUT);
#endif

	digitalWrite(CSN, HIGH);
	pinMode(CSN, OUTPUT);

	SPI.begin();
	SPI.setClockDivider(SPI_CLOCK_DIV2);
#else
	TRX_EN_DDR |= _BV(TRX_EN_BIT);
	PWR_MODE_DDR |= _BV(PWR_MODE_BIT);
	TX_EN_DDR |= _BV(TX_EN_BIT);

#if NRF905_COLLISION_AVOID
	CD_DDR &= ~_BV(CD_BIT);
#endif

#if AM_IS_USED_HW
	AM_DDR &= ~_BV(AM_BIT);
#endif

#if !NRF905_DR_SW
	DR_DDR &= ~_BV(DR_BIT);
#endif

	spiDeselect();
	CSN_DDR |= _BV(CSN_BIT);

	spi_init();
#endif

	radio.state = NRF905_RADIO_STATE_IDLE;

	// Startup
	enableStandbyMode();
	receiveMode();
	nRF905_powerDown();
	_delay_ms(3);
	defaultConfig();

#if NRF905_INTERRUPTS
	// Set interrupts
	REG_EXTERNAL_INT_CTL |= BIT_EXTERNAL_INT_CTL;
	nRF905_interrupt_on();
#endif

	nRF905_powerUp();
}
Esempio n. 26
0
void AMLED::init(int pin) {
	this->pin = pin;

	pinMode(pin, OUTPUT);
	digitalWrite(pin, LOW);
}
Esempio n. 27
0
void setup(){
  //delay(10000);
  //setup the accelerometer and screen
  //Serial.begin(9600); 
  //Serial.print("IPA"); //to vdip logger
  //Serial.print(13, BYTE); //to vdip logger
  //delay(10000);
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(sprayTriggerPin, OUTPUT);
  digitalWrite(sprayTriggerPin, LOW);
  LCDSerial.begin(9600);
  //put wait code to look and see if there is a
  //response from the VDIP1.  If there isn't try connecting again
  
  //read the root dir in the memstick to set the 
  //log file's name/number (its sequential)
  //Serial.print("DIR");
  //Serial.print(13, BYTE);
  //LCDSerial.print(0xFE, BYTE);   //command flag
   //LCDSerial.print(128, BYTE); 
  //while(Serial.available() > 0){
   //LCDSerial.print(Serial.read()); 
  //}
  
  //LCDSerial.print(0xFE, BYTE);   //command flag
   //LCDSerial.print(128, BYTE); 
  //LCDSerial.print("initialized");
  //read
  //int tfilenum = 0;
  /*if(Serial.available() > 0){
    //look for "LOG"
    int input = Serial.read();
    Serial.print(input);
    if (input == 76){  //L
      input = Serial.read();
       if (input == 79){ //O
       input = Serial.read();
        if (input == 71){ //G
          //get the numers after "LOG"
          input = Serial.read();
          tfilenum = input - 48;
          input = Serial.read();
          while (input > 48 && input < 58){
            input = Serial.read();
            tfilenum = tfilenum * 10 + input - 48;
          }
        } 
      }
    }
  }*/
  
  //logfilecount = tfilenum + 1;
 // Serial.print("OPW LOG555");
  //Serial.print(13, BYTE);
   LCDSerial.print(0xFE, BYTE);   
   LCDSerial.print(192, BYTE);  
   LCDSerial.print("LCD check");
   delay(1000);
  //LCDSerial.print("file write");
  //Serial.print("CFL LOG555");
  //Serial.print(13,BYTE);
  
  //this next line for debug only
  //delay(10000);
  LCDSerial.print(0x7C, BYTE);  
  LCDSerial.print(157, BYTE);   //light level to 150 out of 157
   //LCDSerial.print(0xFE, BYTE);   
   //LCDSerial.print(0x01, BYTE);
  //zero the accelerometer...but only for small tilts
  int tempreading = analogRead(yval);
  if ((tempreading < 600) && (tempreading > 400)){
    zerogy = tempreading;
    LCDSerial.print("1");
  }
  else {
    zerogy = 512;
    LCDSerial.print("2");
  }
  tempreading = analogRead(xval);
  if ((tempreading < 600) && (tempreading > 400)){
    zerogx = tempreading;
  }
  else {
    zerogx = 512;
  }
  //setup the buttons as inputs
  pinMode(buttonApin, INPUT);
  pinMode(buttonBpin, INPUT);
}
Esempio n. 28
0
int main()
{
FILE *fp;
fp= fopen ("logfile.txt","w+");
char inp[5]= "UUUUU"; 
short i=0;
//short length=strlen(inp);
short length=5;
fprintf(fp,"%d ",length);
short j=0,k=0;
short ascii_out[length];
short bit_out[8*length];
short n_zero=0;
//short repeat=3;

while(j<length){
	ascii_out[j] = (int) inp[j];
	fprintf(fp," ascii %d bits ",ascii_out[j]);

	if(ascii_out[j]<2)
		n_zero=7;
	else if(ascii_out[j]<4)
		n_zero=6;
	else if(ascii_out[j]<8)
		n_zero=5;
	else if(ascii_out[j]<16)
		n_zero=4;
	else if(ascii_out[j]<32)
		n_zero=3;
	else if(ascii_out[j]<64)
		n_zero=2;
	else if(ascii_out[j]<128)
		n_zero=1;

	for(k=0;k<n_zero;k++){
		bit_out[8*j+i]=0;
		fprintf(fp,"%d ",bit_out[8*j+i]);
		i++;
	}
	while(ascii_out[j]>0){
		bit_out[8*j+i]=ascii_out[j]%2;
		ascii_out[j]=ascii_out[j]/2;
		fprintf(fp,"%d ",bit_out[8*j+i]);
		i++;
	}
	i=0;
	j++;
}
fclose(fp);

if(wiringPiSetup() == -1)
	exit(1);
pinMode(7,OUTPUT);

while(1){
  j=0;//k=0;
  while(j<8*length){
	//while(k<repeat){
		if(bit_out[j]==1)
			digitalWrite(7,1);
		else if(bit_out[j]==0)
			digitalWrite(7,0);
	//k++;
	//}
     j++;
  }
}
return 0;
}
void AnalogSensor::init(){
    pinMode(_pin, INPUT);
}
	void IRSensor::initPins()
	{
#ifdef __MK20DX256__ // Teensy Compile
		pinMode(DATA_PIN, INPUT);
#endif
	}