本文整理汇总了C++中pinMode函数的典型用法代码示例。如果您正苦于以下问题:C++ pinMode函数的具体用法?C++ pinMode怎么用?C++ pinMode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pinMode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pinMode
void Smarty::setButtonPin(uint8_t pin) {
m_buttonPin = pin;
pinMode(pin, INPUT_PULLUP);
}
示例2: pinMode
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;
}
}
}
}
示例3: pinMode
void decodeurDCF1_c::begin(uint8_t pin)
{
_pin = pin & 127;
pinMode(_pin, INPUT);
}
示例4: A110x2500Gdo0Init
void A110x2500Gdo0Init()
{
pinMode (RF_GDO0, INPUT);
}
示例5: pinMode
/* Constructor. */
Thermistor::Thermistor(int pin, TemperatureUnits units)
{
m_Pin = pin;
pinMode(m_Pin, INPUT);
m_Units = units;
}
示例6: pinMode
//*****Sender Class Begins*****
Sender::Sender (short pinIn, Protocol * protIn){
pin = pinIn;
prot = protIn;
pinMode(pin,OUTPUT);
}
示例7: Plugin_006
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);
//.........这里部分代码省略.........
示例8: servoTurn
/*****************************************************************************************************************************
*
* 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;
}
示例9: pinMode
/**
* 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);
}
示例10: pinModeNonDue
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)
//.........这里部分代码省略.........
示例11: pinMode
void AnalogSwitch::Init(){
if (AnalogPin >= 0 && AnalogPin <= 5)
pinMode(AnalogPin, INPUT); //receive switch signal
}
示例12: micros
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);
}
示例13: pinMode
void MeteoTemp::doStep2()
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
prepareStep3();
}
示例14: pinMode
void LED::setup()
{
pinMode(outPin, OUTPUT);
}
示例15: pinMode
void Ultrasonic::init(){
pinMode(tPin, OUTPUT);
digitalWrite(tPin, 0);
pinMode(ePin, INPUT);
}