本文整理汇总了C++中digitalRead函数的典型用法代码示例。如果您正苦于以下问题:C++ digitalRead函数的具体用法?C++ digitalRead怎么用?C++ digitalRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了digitalRead函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: digitalRead
int buttonModule::readDigital(void){
return digitalRead(pin_number);
}
示例2: digitalToggle
void Digital::digitalToggle(){digitalWrite(!digitalRead());}
示例3: switch
void CmdFixture::handle(char * input)
{
int cntIdx = 0;
char cmd = input[1];
char len = input[0];
if (len < 1) return;
switch (cmd) {
/********** Analog and EEPROM value *******************/
case 0x00: /* get eep voltage min */
cmdRepWord(cmd, eepVoltMin);
break;
case 0x01: /* get eep voltage max */
cmdRepWord(cmd, eepVoltMax);
break;
case 0x02: /* get eep current min */
cmdRepWord(cmd, eepCurrMin);
break;
case 0x03: /* get eep current max */
cmdRepWord(cmd, eepCurrMax);
break;
case 0x04: /* get AD voltage value */
cmdRepAdVal(cmd, 0);
break;
case 0x05: /* get AD current value */
cmdRepAdVal(cmd, 1);
break;
/******************************************************/
/************ Digital monitoring **********************/
case 0x10: /* get Digital 13 (PB5) status */
cmdRepStatus(cmd, digitalRead(StatusOnBoard));
break;
case 0x11: /* get Digital 5 (PD5) status */
cmdRepStatus(cmd, digitalRead(StatusPowerDrop));
break;
case 0x12: /* get Digital 7 (PD7) status */
cmdRepStatus(cmd, digitalRead(StatusCurrentError));
break;
case 0x13: /* get Digital x (Pxx) status */
cmdRepStatus(cmd, digitalRead(StatusPowerOn));
break;
case 0x14: /* get Digital 4 (PD4) status */
cmdRepStatus(cmd, digitalRead(OutputReaderPower));
break;
case 0x15: /* get Bootloader switch status */
cmdRepStatus(cmd, digitalRead(ButtonBootloader));
break;
case 0x16: /* get power switch status */
cmdRepStatus(cmd, digitalRead(ButtonPower));
break;
/******************************************************/
/***************** EEPROM setting *********************/
case 0x20: /* set eep voltage min */
if (len == 3) {
eepVoltMin = word(input[2], input[3]);
writeEepWord(EepAddrVoltMin, eepVoltMin);
cmdRepOnly(cmd);
}
break;
case 0x21: /* set eep voltage max */
if (len == 3) {
eepVoltMax = word(input[2], input[3]);
writeEepWord(EepAddrVoltMax, eepVoltMax);
cmdRepOnly(cmd);
}
break;
case 0x22: /* set eep current min */
if (len == 3) {
eepCurrMin = word(input[2], input[3]);
writeEepWord(EepAddrCurrMin, eepCurrMin);
cmdRepOnly(cmd);
}
break;
case 0x23: /* set eep current max */
if (len == 3) {
eepCurrMax = word(input[2], input[3]);
writeEepWord(EepAddrCurrMax, eepCurrMax);
cmdRepOnly(cmd);
}
break;
/******************************************************/
/***************** Digital setting ********************/
case 0x30: /* set Digital 13 (PB5) */
if (len == 2) {
digitalWrite(StatusOnBoard, input[2]);
cmdRepOnly(cmd);
}
break;
case 0x31: /* set Digital 5 (PD5) */
if (len == 2) {
digitalWrite(StatusPowerDrop, input[2]);
cmdRepOnly(cmd);
}
break;
case 0x32: /* set Digital 7 (PD7) */
if (len == 2) {
digitalWrite(StatusCurrentError, input[2]);
//.........这里部分代码省略.........
示例4: getButton
boolean Reflowster::getButton() {
return !digitalRead(pinConfiguration_encoderButton);
}
示例5: waitUntil
bool waitUntil(int pin, bool pos) {
while (digitalRead(pin) != pos);
return true;
}
示例6: main
main()
{
struct timespec tp1, tp2;
long timp1, timp2, timp3;
int i1,i2,x,y;
int count;
int s1;
long double s2;
long double accum;
long double accum1;
struct timespec clock_resolution;
int stat;
wiringPiSetup () ;
pinMode (7, INPUT) ;
printf("Start\n");
stat = clock_getres(CLOCK_REALTIME, &clock_resolution);
printf("Clock resolution is %d seconds, %ld nanoseconds\n", clock_resolution.tv_sec, clock_resolution.tv_nsec);
clock_gettime(CLOCK_REALTIME, &tp1);
count=0;
while ( count < 200000 )
{
while ( digitalRead(7) == LOW )
{
}
count++;
while ( digitalRead(7) == HIGH )
{
}
count++;
}
clock_gettime(CLOCK_REALTIME, &tp2);
s1 = tp2.tv_sec-tp1.tv_sec;
clock_gettime(CLOCK_REALTIME, &tp1);
count=0;
while ( count < 200000 )
{
while ( digitalRead(7) == LOW )
{
}
count++;
while ( digitalRead(7) == HIGH )
{
}
count++;
}
clock_gettime(CLOCK_REALTIME, &tp2);
s1 = tp2.tv_sec-tp1.tv_sec;
s2 = tp2.tv_nsec-tp1.tv_nsec;
accum = ( tp2.tv_nsec - tp1.tv_nsec );
accum1= accum;
if ( accum<0 )
{
accum=accum+1000000000;
printf(" acumulator atenuat \n");
}
accum1=accum1+s1*1000000000;
printf( "ACCUM %lf \n", accum );
printf( "!! ACCUM1 %lf !! \n", accum1);
printf(" dif1 calcul scadere secunde %ld \n",s1);
printf(" dif2 calcul scadere nanosec %ld \n",s2);
printf(" Rez citit secunde %d %d \n",tp1.tv_sec, tp1.tv_nsec);
printf(" Rez citit nanosec %ld %lld \n",tp2.tv_sec, tp2.tv_nsec);
printf(" Rez calc sec %ld \n",tp2.tv_sec-tp1.tv_sec);
printf(" Rez calc nanosec %ld \n",tp2.tv_nsec-tp1.tv_nsec);
printf("Stop\n");
}
示例7: digitalRead
boolean Reflowster::relayStatus() {
return digitalRead(pinConfiguration_relay);
}
示例8: digitalRead
// Poll for OOK signal
bool RFM69OOK::poll()
{
return digitalRead(_interruptPin);
}
示例9: set_alarm_1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Function to set Alarm time 1
void set_alarm_1(){
if (digitalRead(button_set_mins_in) == HIGH){ //check minutes button
if(alarm_1_time==2400){ alarm_1_time = 0; }
alarm_1_time++; //add one minute to offset
beep();
Serial.print("Increment alarm minutes ");
Serial.print(alarm_1_time);
Serial.print("\n");
delay(200);
}
if (digitalRead(button_set_hrs_in) == HIGH){ //check hours button
if(alarm_1_time==2400){ alarm_1_time = 0; }
alarm_1_time += 100; //add 60*1 minutes to offset the time
beep();
Serial.print("Increment alarm hours ");
Serial.print(alarm_1_time);
Serial.print("\n");
delay(200);
}
if(alarm_1_time%100 == 60){ //alarm time is now maybe 1260, but it should not be!
alarm_1_time += 40; //alarm time goes to 1300
Serial.print("Alarm 1 time corrected to +40\n");
}
if(alarm_1_time > 2359){ //alarm time is now 2401, but it should not be!
alarm_1_time = 2400; //alarm time goes to 0000
Serial.print("Alarm 1 time corrected to 0000\n");
}
Serial.print("Alarm 1 time: ");
Serial.print(alarm_1_time);
Serial.print("\n");
gettime();
//Now make the display blink while setting the Alarm 1 time.
if((millis_left%1000) > 500){ //0.5 seconds lit up
if(alarm_1_time == 2400){ //If alarm is deactivated from user
matrix.drawColon(false);
matrix.writeDigitRaw(0,B01000000); //"-"
matrix.writeDigitRaw(1,B01000000); //"-"
matrix.writeDigitRaw(3,B01000000); //"-"
matrix.writeDigitRaw(4,B01000000); //"-"
matrix.writeDisplay();
}
else{
a1h1 = alarm_1_time/1000;
a1h2 = ( alarm_1_time - a1h1 * 1000 ) / 100;
a1m3 = ( alarm_1_time - a1h1 * 1000 - a1h2 * 100 ) / 10;
a1m4 = alarm_1_time % 10;
matrix.drawColon(true);
matrix.writeDigitNum(0, a1h1);
matrix.writeDigitNum(1, a1h2);
matrix.writeDigitNum(3, a1m3);
matrix.writeDigitNum(4, a1m4);
matrix.writeDisplay();
}
}
else{
matrix.drawColon(false); //0.5 seconds lit off
matrix.writeDigitRaw(0,B00000000); //" "
matrix.writeDigitRaw(1,B00000000); //" "
matrix.writeDigitRaw(3,B00000000); //" "
matrix.writeDigitRaw(4,B00000000); //" "
matrix.writeDisplay();
}
}
示例10: main
/*
* The main method initializes the gpios and starts a thread and checks the content
* of the files.
*/
int main() {
int res;
int count, statusBefore, statusAfter, sensorBefore, sensorAfter;
struct timespec sleeptime, result, sensorResult;
struct timespec before, measureSensorBefore;
struct timespec after, measureSensorAfter;
uint16_t distance;
sleeptime.tv_sec = 0;
sleeptime.tv_nsec = 000010000L; // sleep 10µs
int maxPriority;
int status;
// get max available priority
maxPriority = sched_get_priority_max(SCHED_FIFO);
if (maxPriority == -1) {
perror("Could not determine the maximum priority available.");
exit(EXIT_FAILURE);
}
// set scheduler to SCHED_FIFO and priority to max priority
struct sched_param sched;
sched.sched_priority = maxPriority;
status = sched_setscheduler(0, SCHED_FIFO, &sched);
if (status) {
perror("ERROR: Could not set real time priority (are you running this as root?)");
exit(EXIT_FAILURE);
}
// TODO: Add comment for the above sleeptime: How much µs / ms whatever is this? -> use human readable unit here!
/*signal(SIGINT, sigfunc); */
wiringPiSetupGpio();
pinMode(GPIO_TRIGGER, OUTPUT);
pinMode(GPIO_ECHO, INPUT);
statusBefore = clock_gettime(CLOCK_MONOTONIC, &before);
digitalWrite(GPIO_TRIGGER, 1);
if(clock_nanosleep(CLOCK_MONOTONIC, 0, &sleeptime, NULL))
{
perror("nanosleep failed\n");
exit(EXIT_FAILURE);
}
digitalWrite(GPIO_TRIGGER, 0);
while(1) {
if(digitalRead(GPIO_ECHO) == 1) {
sensorBefore = clock_gettime(CLOCK_MONOTONIC, &measureSensorBefore);
break;
}
}
while(1) {
if(digitalRead(GPIO_ECHO) == 0) {
sensorAfter = clock_gettime(CLOCK_MONOTONIC, &measureSensorAfter);
break;
}
}
/* A bit of theory:
* Max distance of ultrasonic sensor: about 3m
* -> So the max time for the sound to travel to a barrier
* and back for this distance is (at 19.2 degree celsius):
* 6m / 343m/s = 0.017492711s = 17492711ns
* => max number in result.tv_nsec is 17492711ns
*
* 17492711 * 343 = 5999999873 ==> this is the max number which must be
* stored in the meantime during the calculation.
* Max no to be stored: 5999999873
* Max no in long : 4294967295
* --> so we need to use an usigned *long long* in the following..
*/
sensorResult = diffTime(measureSensorBefore, measureSensorAfter);
distance = (uint64_t) sensorResult.tv_nsec * 343 / 1000000 / 2;
statusAfter = clock_gettime(CLOCK_MONOTONIC, &after);
result = diffTime(before, after);
printf("seconds: %ld nanoseconds %ld\n", result.tv_sec, result.tv_nsec);
printf("Result: %hu\n\n", distance);
delay(20);
return(EXIT_SUCCESS);
}
示例11: snes_is_on
int snes_is_on (void)
{
return digitalRead (PIN_SNES_VCC);
}
示例12: digitalWrite
void *ChangeTHRepresentation (void *param)
{
(void)param;
OCStackResult result = OC_STACK_ERROR;
modCounter += 1;
if (modCounter % 10 ==
0) // Matching the timing that the Linux Sample Server App uses for the same functionality.
{
byte dht11_dat[5];
byte i;// start condition
digitalWrite(dht11_pin, LOW);
delay(18);
digitalWrite(dht11_pin, HIGH);
delayMicroseconds(1);
pinMode(dht11_pin, INPUT);
delayMicroseconds(40);
if (digitalRead(dht11_pin))
{
Serial.println("dht11 start condition 1 not met"); // wait for DHT response signal: LOW
delay(1000);
return NULL;
}
delayMicroseconds(80);
if (!digitalRead(dht11_pin))
{
Serial.println("dht11 start condition 2 not met"); //wair for second response signal:HIGH
return NULL;
}
delayMicroseconds(80);// now ready for data reception
for (i = 0; i < 5; i++)
{
dht11_dat[i] = read_dht11_dat();
} //recieved 40 bits data. Details are described in datasheet
pinMode(dht11_pin, OUTPUT);
digitalWrite(dht11_pin, HIGH);
byte dht11_check_sum = dht11_dat[0] + dht11_dat[2]; // check check_sum
if (dht11_dat[4] != dht11_check_sum)
{
Serial.println("DHT11 checksum error");
}
Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.println("C ");
TH.m_humid = dht11_dat[0];
TH.m_temp = dht11_dat[2];
if (g_THUnderObservation)
{
OC_LOG_V(INFO, TAG, " =====> Notifying stack of new humid level %d\n", TH.m_humid);
OC_LOG_V(INFO, TAG, " =====> Notifying stack of new temp level %d\n", TH.m_temp);
result = OCNotifyAllObservers (TH.m_handle, OC_NA_QOS);
if (OC_STACK_NO_OBSERVERS == result)
{
g_THUnderObservation = 0;
}
}
}
return NULL;
}
示例13: 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;
}
}
}
示例14: cc3k_int_poll
void cc3k_int_poll()
{
if (digitalRead(g_irqPin) == LOW && ccspi_is_in_irq == 0 && ccspi_int_enabled != 0) {
SPI_IRQ();
}
}
示例15: alarm_beep
void alarm_beep(){
int count0 = 0;
do{
count0++;
int count = 0; //cut the beep at some point
writetime();
drawDots();
delay(20);
digitalWrite(led_RGB_1, HIGH);
digitalWrite(led_RGB_2, HIGH);
if( count0%3 == 0 ){
print_sad(); //Print a sad smile
delay(300);
}
//Serial.print("In alarm - beep \n");
beep();
delay(100);
beep();
delay(100);
beep();
delay(150);
if (digitalRead(alarm_off_1) == HIGH){
//Serial.print("One 1 end touched :) \n");
digitalWrite(led_RGB_1, LOW);
print_smile();
delay(500);
do{
//Now beep less
if(count%5 == 0) {
beep();
}
count++;
writetime();
drawDots();
if (digitalRead(alarm_off_2) == HIGH){
//Alarm off
//Serial.print("Other 2 end touched, alarm = 0 \n");
digitalWrite(led_RGB_2, LOW);
alarm = 0;
break;
}
//Serial.print("In while loop 1! \n");
delay(100);
}
while(digitalRead(alarm_wire) == LOW || alarm == 0);
delay(100);
//Serial.print("While loop exited, now exit alarm \n");
}
else if (digitalRead(alarm_off_2) == HIGH){
//Serial.print("One 2 end touched :) \n");
digitalWrite(led_RGB_2, LOW);
print_smile();
delay(500);
do{
//Now beep less
if(count%5 == 0) {
beep();
}
count++;
writetime();
drawDots();
if (digitalRead(alarm_off_1) == HIGH){
//Alarm off
//Serial.print("Other 1 end touched, alarm = 0 \n");
digitalWrite(led_RGB_1, LOW);
alarm = 0;
break;
}
Serial.print("In while loop 2! \n");
delay(100);
}
while(digitalRead(alarm_wire) == LOW || alarm == 0);
delay(100);
//Serial.print("While loop exited, now exit alarm \n");
//exit;
}
}
while( alarm != 0 );
print_smile(); //Show a smile
delay(700);
print_alarm_off();
//Serial.print("I said!!!!! Exit alarm loop: Alarm = ");
//Serial.print(alarm);
//Serial.print("\n");
//.........这里部分代码省略.........