本文整理汇总了C++中digitalWrite函数的典型用法代码示例。如果您正苦于以下问题:C++ digitalWrite函数的具体用法?C++ digitalWrite怎么用?C++ digitalWrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了digitalWrite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pinMode
void DHT::begin(void) {
// set up the pins!
pinMode(_pin, INPUT);
digitalWrite(_pin, HIGH);
_lastreadtime = 0;
}
示例2: main
int main(void)
{
init();
// proceed depending on the bootloader version
if( Utils.getBootVersion() >= 'E')
{
pinMode(RTC_SLEEP, OUTPUT);
digitalWrite(RTC_SLEEP, HIGH);
}
// Check OTA EEPROM flag and mark flag in Waspmote
// Control Register if corresponds to
if( Utils.readEEPROM(0x01) == 0x01 )
{
// set register flag
WaspRegister |= REG_OTA;
// clear eeprom flag
eeprom_write_byte((unsigned char *) 0x01, 0x00);
}
delay(3);
if( WaspRegister & REG_SX )
{
delay(3);
// Powering the module
pinMode(XBEE_PW,OUTPUT);
delay(3);
digitalWrite(XBEE_PW,HIGH);
delay(3);
//Configure the MISO, MOSI, CS, SPCR.
SPI.begin();
delay(3);
//Set Most significant bit first
SPI.setBitOrder(MSBFIRST);
delay(3);
//Divide the clock frequency
SPI.setClockDivider(SPI_CLOCK_DIV2);
delay(3);
//Set data mode
SPI.setDataMode(SPI_MODE0);
delay(3);
//finish
SPI.end();
delay(3);
// disable all SPI slaves
SPI.setSPISlave(ALL_DESELECTED);
delay(3);
// Powering the module
pinMode(XBEE_PW,OUTPUT);
digitalWrite(XBEE_PW,LOW);
delay(3);
}
delay(3);
// get serial id
_serial_id = Utils.readSerialID();
// set random seed
srand(_serial_id);
setup();
for (;;) {
loop();
}
return 0;
}
示例3: loop
// Main arduino loop.
void loop() {
short v;
byte t;
int p;
rov_servo *s;
if (!is_waiting && Serial.available() > 32) {
Serial.write(OP_SHOULDWAIT);
is_waiting = true;
return;
} else if (is_waiting && Serial.available() < 16) {
Serial.write(OP_SHOULDSTART);
is_waiting = false;
return;
} else if (Serial.available() > 0) {
switch(Serial.read()) {
case OP_SERVO_WRITE:
while(!Serial.available());
p = Serial.read();
while(!Serial.available());
v = Serial.read();
if (s = lookup_servo(p)) { // Find the servo object on this pin.
s->s.write(v);
}
break;
case OP_DIGITAL_ON:
while (!Serial.available());
digitalWrite(Serial.read(),HIGH);
break;
case OP_DIGITAL_OFF:
while (!Serial.available());
digitalWrite(Serial.read(),LOW);
break;
case OP_DIGITAL_READ:
while(!Serial.available());
v = (digitalRead(Serial.read()) == HIGH) ? 1 : 0;
Serial.write((uint8_t*) &v,2);
break;
case OP_ANALOG_WRITE:
while (!Serial.available());
p = Serial.read();
while (!Serial.available());
v = Serial.read();
analogWrite(p,v);
break;
case OP_ANALOG_READ:
while (!Serial.available());
v = analogRead(Serial.read());
Serial.write((uint8_t*) &v,2);
break;
case OP_SET_PINSTATE:
while (!Serial.available());
t = Serial.read();
p = t & 0x3f; // Get the pin number.
if (s = lookup_servo(p)) { // Detach any servos on this pin.
s->s.detach();
s->p = -1;
}
t = (t & 0xc0) >> 6;
if (t == ROV_SERVO) {
for (v = 0; v < SERVOC; v++) {
if (servov[v].p == -1) { // Find a free servo.
s = &servov[v];
s->p = p;
s->s.attach(p,1000,2000);
s->s.write(90);
break;
}
}
} else if (t == INPUT_PULLUP) {
pinMode(p,INPUT_PULLUP);
} else {
pinMode(p,(t) ? OUTPUT : INPUT);
}
break;
}
}
}
示例4: pinMode
void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
_vccstate = vccstate;
_i2caddr = i2caddr;
// set pin directions
if (sid != -1) {
pinMode(dc, OUTPUT);
pinMode(cs, OUTPUT);
csport = portOutputRegister(digitalPinToPort(cs));
cspinmask = digitalPinToBitMask(cs);
dcport = portOutputRegister(digitalPinToPort(dc));
dcpinmask = digitalPinToBitMask(dc);
if (!hwSPI) {
// set pins for software-SPI
pinMode(sid, OUTPUT);
pinMode(sclk, OUTPUT);
clkport = portOutputRegister(digitalPinToPort(sclk));
clkpinmask = digitalPinToBitMask(sclk);
mosiport = portOutputRegister(digitalPinToPort(sid));
mosipinmask = digitalPinToBitMask(sid);
}
if (hwSPI) {
SPI.begin ();
//#ifdef __SAM3X8E__
SPI.setClockDivider (9); // 9.3 MHz
//#else
// SPI.setClockDivider (SPI_CLOCK_DIV2); // 8 MHz
//#endif
}
}
else
{
// I2C Init
HWIRE.begin();
#ifdef __SAM3X8E__
// Force 400 KHz I2C, rawr! (Uses pins 20, 21 for SDA, SCL)
TWI1->TWI_CWGR = 0;
TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101;
#endif
}
if (reset) {
// Setup reset pin direction (used by both SPI and I2C)
pinMode(rst, OUTPUT);
digitalWrite(rst, HIGH);
// VDD (3.3V) goes high at start, lets just chill for a ms
delay(1);
// bring reset low
digitalWrite(rst, LOW);
// wait 10ms
delay(10);
// bring out of reset
digitalWrite(rst, HIGH);
// turn on VCC (9V?)
}
#if defined SSD1306_128_32
// Init sequence for 128x32 OLED module
ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
ssd1306_command(0x80); // the suggested ratio 0x80
ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
ssd1306_command(0x1F);
ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
ssd1306_command(0x0); // no offset
ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0
ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC)
{
ssd1306_command(0x10);
}
else
{
ssd1306_command(0x14);
}
ssd1306_command(SSD1306_MEMORYMODE); // 0x20
ssd1306_command(0x00); // 0x0 act like ks0108
ssd1306_command(SSD1306_SEGREMAP | 0x1);
ssd1306_command(SSD1306_COMSCANDEC);
ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
ssd1306_command(0x02);
ssd1306_command(SSD1306_SETCONTRAST); // 0x81
ssd1306_command(0x8F);
ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC)
{
ssd1306_command(0x22);
}
else
{
ssd1306_command(0xF1);
}
ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
ssd1306_command(0x40);
ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
#endif
#if defined SSD1306_128_64
//.........这里部分代码省略.........
示例5: digitalWrite
void AmbulanceC::TapOff(){
if(tapTimeout!=NULL) tapTimeout->deleteTimer();
if(dbg) Serial.println("Tap OFF");
digitalWrite(o_Sink, LOW);}
示例6: StatusLEDOFF
void AmbulanceC::StatusLEDOFF(void){digitalWrite(o_StatusLED,LOW);}
示例7: pinMode
/**
* @brief Beeper::stop_beep
*/
void Beeper::stop_beep()
{
pinMode(this->pin, OUTPUT);
digitalWrite(this->pin, LOW);
this->is_beeping = false;
}
示例8: pinMode
void AmbulanceC::initializePins(){
//initialize outputs
pinMode(o_SrnOff, OUTPUT); digitalWrite(o_SrnOff, LOW);
pinMode(o_SrnOn, OUTPUT); digitalWrite(o_SrnOn, LOW);
pinMode(o_LHScene, OUTPUT); digitalWrite(o_LHScene, LOW);
pinMode(o_RHScene, OUTPUT); digitalWrite(o_RHScene, LOW);
pinMode(o_AlPow, OUTPUT); digitalWrite(o_AlPow, LOW);
pinMode(o_Sink, OUTPUT); digitalWrite(o_Sink, LOW);
pinMode(23, OUTPUT); digitalWrite(23, LOW);
pinMode(25, OUTPUT); digitalWrite(25, LOW);
pinMode(o_LED1, OUTPUT); digitalWrite(o_LED1, LOW);
pinMode(o_LED3, OUTPUT); digitalWrite(o_LED3, LOW);
pinMode(o_StatusLED, OUTPUT); digitalWrite(o_StatusLED, LOW);
pinMode(o_AlLED, OUTPUT); digitalWrite(o_AlLED, LOW);
pinMode(o_LED5, OUTPUT); digitalWrite(o_LED5, LOW);
//Listening, pull-ups
pinMode(i_pirTamp, INPUT); digitalWrite(i_pirTamp, HIGH);
pinMode(i_pirAl, INPUT); digitalWrite(i_pirAl, HIGH);
pinMode(i_TotAlSw, INPUT); digitalWrite(i_TotAlSw, HIGH);
pinMode(i_PerAlSw, INPUT); digitalWrite(i_PerAlSw, HIGH);
pinMode(i_DoorSw, INPUT); digitalWrite(i_DoorSw, HIGH);
pinMode(i_IsoSw, INPUT); digitalWrite(i_IsoSw, HIGH);
pinMode(i_EmSw, INPUT); digitalWrite(i_EmSw, HIGH);
pinMode(i_HbrkSw, INPUT); digitalWrite(i_HbrkSw, HIGH);
pinMode(i_TapSw, INPUT); digitalWrite(i_TapSw, HIGH);
}
示例9: switch
status_t LSM6DS3Core::beginCore(void)
{
status_t returnError = IMU_SUCCESS;
switch (commInterface) {
case I2C_MODE:
Wire.begin();
break;
case SPI_MODE:
// start the SPI library:
SPI.begin();
// Maximum SPI frequency is 10MHz, could divide by 2 here:
SPI.setClockDivider(SPI_CLOCK_DIV4);
// Data is read and written MSb first.
#ifdef ESP32
SPI.setBitOrder(SPI_MSBFIRST);
#elif ESP8266
SPI.setBitOrder(SPI_MSBFIRST);
#else
SPI.setBitOrder(MSBFIRST);
#endif
// Data is captured on rising edge of clock (CPHA = 0)
// Base value of the clock is HIGH (CPOL = 1)
// MODE3 for 328p operation
#ifdef __AVR__
SPI.setDataMode(SPI_MODE3);
#else
#endif
// MODE0 for Teensy 3.1 operation
#ifdef __MK20DX256__
SPI.setDataMode(SPI_MODE0);
#else
#endif
// initalize the data ready and chip select pins:
pinMode(chipSelectPin, OUTPUT);
digitalWrite(chipSelectPin, HIGH);
break;
default:
break;
}
//Spin for a few ms
volatile uint8_t temp = 0;
for( uint16_t i = 0; i < 10000; i++ )
{
temp++;
}
//Check the ID register to determine if the operation was a success.
uint8_t readCheck;
readRegister(&readCheck, LSM6DS3_ACC_GYRO_WHO_AM_I_REG);
if( readCheck != 0x69 )
{
returnError = IMU_HW_ERROR;
}
return returnError;
}
示例10: digitalWrite
void Mrf24j::reset(void) {
digitalWrite(_pin_reset, LOW);
delay(10); // just my gut
digitalWrite(_pin_reset, HIGH);
delay(20); // from manual
}
示例11: maskToBitNum
uint8_t PSX64::config_gamepad(uint8_t clk, uint8_t cmd, uint8_t att, uint8_t dat, bool pressures, bool rumble) {
uint8_t temp[sizeof(type_read)];
_clk_mask = maskToBitNum(digitalPinToBitMask(clk));
_clk_oreg = portOutputRegister(digitalPinToPort(clk));
_cmd_mask = maskToBitNum(digitalPinToBitMask(cmd));
_cmd_oreg = portOutputRegister(digitalPinToPort(cmd));
_att_mask = maskToBitNum(digitalPinToBitMask(att));
_att_oreg = portOutputRegister(digitalPinToPort(att));
_dat_mask = maskToBitNum(digitalPinToBitMask(dat));
_dat_ireg = portInputRegister(digitalPinToPort(dat));
pinMode(clk, OUTPUT); //configure ports
pinMode(att, OUTPUT);
pinMode(cmd, OUTPUT);
pinMode(dat, INPUT);
digitalWrite(dat, HIGH); //enable pull-up
SET(*_cmd_oreg,_cmd_mask); // SET(*_cmd_oreg,_cmd_mask);
SET(*_clk_oreg,_clk_mask);
//new error checking. First, read gamepad a few times to see if it's talking
read_gamepad();
read_gamepad();
//see if it talked
if(PS2data[1] != 0x41 && PS2data[1] != 0x73 && PS2data[1] != 0x79){ //see if mode came back. If still anything but 41, 73 or 79, then it's not talking
#ifdef PSX64_DEBUG
Serial.println("Controller mode not matched or no controller found");
Serial.print("Expected 0x41 or 0x73, got ");
Serial.println(PS2data[1], HEX);
#endif
return 1; //return error code 1
}
//try setting mode, increasing delays if need be.
read_delay = 1;
for(int y = 0; y <= 10; y++)
{
sendCommandString(enter_config, sizeof(enter_config)); //start config run
//read type
delayMicroseconds(CTRL_BYTE_DELAY);
SET(*_cmd_oreg,_cmd_mask);
SET(*_clk_oreg,_clk_mask);
CLR(*_att_oreg,_att_mask); // low enable joystick
delayMicroseconds(CTRL_BYTE_DELAY);
for (int i = 0; i<9; i++) {
temp[i] = _gamepad_shiftinout(type_read[i]);
}
SET(*_att_oreg,_att_mask); // HI disable joystick
controller_type = temp[3];
sendCommandString(set_mode, sizeof(set_mode));
if(rumble){ sendCommandString(enable_rumble, sizeof(enable_rumble)); en_Rumble = true; }
if(pressures){ sendCommandString(set_bytes_large, sizeof(set_bytes_large)); en_Pressures = true; }
sendCommandString(exit_config, sizeof(exit_config));
read_gamepad();
if(pressures){
if(PS2data[1] == 0x79)
break;
if(PS2data[1] == 0x73)
return 3;
}
if(PS2data[1] == 0x73)
break;
if(y == 10){
#ifdef PSX64_DEBUG
Serial.println("Controller not accepting commands");
Serial.print("mode stil set at");
Serial.println(PS2data[1], HEX);
#endif
return 2; //exit function with error
}
read_delay += 1; //add 1ms to read_delay
}
return 0; //no error if here
}
示例12: TapOn
//Tap///////////////////////////////////////////////////////////////////////////////////
void AmbulanceC::TapOn(void){digitalWrite(o_Sink, HIGH);
if(dbg) Serial.println("Tap ON");
tapTimeout=t.setTimeout(60000, TAPOFF);
}
示例13: AlLEDL
void AmbulanceC::AlLEDL(){digitalWrite(o_AlLED,LOW);}
示例14: AlLEDH
void AmbulanceC::AlLEDH(){digitalWrite(o_AlLED,HIGH);}
示例15: delayMicroseconds
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;
_currline = 0;
// for some 1 line displays you can select a 10 pixel high font
if ((dotsize != 0) && (lines == 1)) {
_displayfunction |= LCD_5x10DOTS;
}
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
delayMicroseconds(50000);
// Now we pull both RS and R/W low to begin commands
digitalWrite(_rs_pin, LOW);
digitalWrite(_enable_pin, LOW);
if (_rw_pin != 255) {
digitalWrite(_rw_pin, LOW);
}
//put the LCD into 4 bit or 8 bit mode
if (! (_displayfunction & LCD_8BITMODE)) {
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46
// we start in 8bit mode, try to set 4 bit mode
write4bits(0x03);
delayMicroseconds(4500); // wait min 4.1ms
// second try
write4bits(0x03);
delayMicroseconds(4500); // wait min 4.1ms
// third go!
write4bits(0x03);
delayMicroseconds(150);
// finally, set to 4-bit interface
write4bits(0x02);
} else {
// this is according to the hitachi HD44780 datasheet
// page 45 figure 23
// Send function set command sequence
command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(4500); // wait more than 4.1ms
// second try
command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(150);
// third go
command(LCD_FUNCTIONSET | _displayfunction);
}
// finally, set # lines, font size, etc.
command(LCD_FUNCTIONSET | _displayfunction);
// turn the display on with no cursor or blinking default
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
display();
// clear it off
clear();
// Initialize to default text direction (for romance languages)
_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
// set the entry mode
command(LCD_ENTRYMODESET | _displaymode);
}