• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ digitalRead函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中digitalRead函数的典型用法代码示例。如果您正苦于以下问题:C++ digitalRead函数的具体用法?C++ digitalRead怎么用?C++ digitalRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了digitalRead函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: digitalRead

int buttonModule::readDigital(void){
	return digitalRead(pin_number);
}
开发者ID:KAsimov-,项目名称:DRIMLINER,代码行数:3,代码来源:DRIMLINER.cpp


示例2: digitalToggle

void Digital::digitalToggle(){digitalWrite(!digitalRead());}
开发者ID:risa150,项目名称:SRC,代码行数:1,代码来源:digital.cpp


示例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]);
//.........这里部分代码省略.........
开发者ID:qoopooh,项目名称:try_git,代码行数:101,代码来源:cmdfixture.cpp


示例4: getButton

boolean Reflowster::getButton() {
  return !digitalRead(pinConfiguration_encoderButton);
}
开发者ID:julianh2o,项目名称:Reflow-Controller,代码行数:3,代码来源:Reflowster.cpp


示例5: waitUntil

bool waitUntil(int pin, bool pos) {
    while (digitalRead(pin) != pos);
    return true;
}
开发者ID:tpavlek,项目名称:arduitron,代码行数:4,代码来源:tron.cpp


示例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");
  
}
开发者ID:RaresPlescan,项目名称:daisypi,代码行数:94,代码来源:t3.c


示例7: digitalRead

boolean Reflowster::relayStatus() {
  return digitalRead(pinConfiguration_relay);
}
开发者ID:julianh2o,项目名称:Reflow-Controller,代码行数:3,代码来源:Reflowster.cpp


示例8: digitalRead

// Poll for OOK signal
bool RFM69OOK::poll()
{
  return digitalRead(_interruptPin);
}
开发者ID:kobuki,项目名称:RFM69OOK,代码行数:5,代码来源:RFM69OOK.cpp


示例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();
    }
    
}
开发者ID:plantpark,项目名称:buzz-wire,代码行数:80,代码来源:buzzwire.c


示例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);
}
开发者ID:Dav1dS1mon,项目名称:de.htwg.resy.robot,代码行数:99,代码来源:distance_test.c


示例11: snes_is_on

int snes_is_on (void)
{
  return digitalRead (PIN_SNES_VCC);
}
开发者ID:SonnyJim,项目名称:snesbot,代码行数:4,代码来源:snesbot.c


示例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;
}
开发者ID:MCherifiOSS,项目名称:iotivity,代码行数:70,代码来源:thserver.cpp


示例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;
        }
    }
}
开发者ID:Wentworth-MATE-ROV,项目名称:mate-rov-src,代码行数:78,代码来源:arduino.c


示例14: cc3k_int_poll

void cc3k_int_poll()
{
  if (digitalRead(g_irqPin) == LOW && ccspi_is_in_irq == 0 && ccspi_int_enabled != 0) {
    SPI_IRQ();
  }
}
开发者ID:klinker41,项目名称:pushbullet-arduino,代码行数:6,代码来源:ccspi.cpp


示例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");
//.........这里部分代码省略.........
开发者ID:plantpark,项目名称:buzz-wire,代码行数:101,代码来源:buzzwire.c


示例16: digitalRead

int Switch::val ()
{
	value = digitalRead (pin);
}
开发者ID:standav,项目名称:tbt-emergency-system,代码行数:4,代码来源:switch.cpp


示例17: loop

void loop() {
    
    
    //Write time
    Serial.print(" --- Time \n");
    writetime();
    delay(30);
    
    
    //Draw dots
    drawDots();
    delay(30);
    
    
    //Check whether to go into settings mode
    if(digitalRead(button_settings_in) == HIGH){
        beep();
        Serial.print("In settings \n");
        settings();
    }
    delay(30);
    
    
    //Now check if we have alarm acivated!
    gettime();
    //Serial.print("Before: Alarm = ");
    //Serial.print(alarm);
    //Serial.print("\n");
    //delay(30);
    if( time == alarm_1_time && alarm){
        //alarm = 0;
        alarm_beep();  //Play the beep
        Serial.print("NO MORE BEEP \n");
        delay(500);
    }
    else if(time != alarm_1_time) alarm = 1;
    //Serial.print("After: Alarm = ");
    //Serial.print(alarm);
    //Serial.print("\n");
    //Serial.print("NO ALARM \n");
    //delay(60);
    
    //Check brightness
    if (digitalRead(button_set_mins_in) == HIGH){ //check minutes button
        brightness++; //increase brightness
        beep();
        if( brightness > 15 ) { brightness = 15; delay(beep_delay); beep(); delay(beep_delay); beep(); }
        matrix.setBrightness(brightness);
        Serial.print("Brightness level changed:");
        Serial.print(brightness);
        Serial.print("\n");
        delay(150);
    }
    if (digitalRead(button_set_hrs_in) == HIGH){ //check hours button
        brightness--; //decrease brightness
        beep();
        if( brightness < 0 ) { brightness = 0; delay(beep_delay); beep(); delay(beep_delay); beep(); }
        matrix.setBrightness(brightness);
        Serial.print("Brightness level changed:");
        Serial.print(brightness);
        Serial.print("\n");
        delay(150);
    }
    
}
开发者ID:plantpark,项目名称:buzz-wire,代码行数:65,代码来源:buzzwire.c


示例18: manualControl

void Stage::loop()
{

  //Check for manual commands
  manualControl();

  //Test limit switches to prevent driving stage past limits
  if(!digitalRead(Z_ULIMIT_SWITCH) && (getDistanceToGo(Z_STEPPER) > 0)){
    Move(Z_STEPPER,0);
  }
  if(!digitalRead(Z_LLIMIT_SWITCH) && (getDistanceToGo(Z_STEPPER) < 0)){
     Move(Z_STEPPER,0);;
  }

  //Called on every loop to enable non-blocking control of steppers
  if((millis()-_z_last_step)>_z_interval){
    if((_z_target-_z_pos)>0){
      z_1_motor->onestep(FORWARD, DOUBLE);
      z_2_motor->onestep(FORWARD, DOUBLE);
      _z_last_step = millis();
      _z_pos++;
    }
    else if((_z_target-_z_pos)<0){
       z_1_motor->onestep(BACKWARD, DOUBLE);
       z_2_motor->onestep(BACKWARD, DOUBLE);
       _z_last_step = millis();
       _z_pos--;
    }
  }

  if((millis()-_xy_last_step)>_xy_interval){

    if((_x_target-_x_pos)>0 && (_y_target-_y_pos)>0){
      //Move up and right
      xy_a_motor->onestep(FORWARD, INTERLEAVE);
      _xy_last_step = millis();
      _x_pos++;
      _y_pos++;
    }
    else if((_x_target-_x_pos)>0 && (_y_target-_y_pos)<0){
      //Move down and right
      xy_b_motor->onestep(FORWARD, INTERLEAVE);
      _xy_last_step = millis();
      _x_pos++;
      _y_pos--;
    }
     else if((_x_target-_x_pos)<0 && (_y_target-_y_pos)>0){
      //Move up and left
      xy_b_motor->onestep(BACKWARD, INTERLEAVE);
      _xy_last_step = millis();
      _x_pos--;
      _y_pos++;
    }
     else if((_x_target-_x_pos)<0 && (_y_target-_y_pos)<0){
      //Move down and left
      xy_a_motor->onestep(BACKWARD, INTERLEAVE);
      _xy_last_step = millis();
      _x_pos--;
      _y_pos--;
    }
     else if((_x_target-_x_pos)==0 && (_y_target-_y_pos)>0){
      //Move up
      xy_a_motor->onestep(FORWARD, INTERLEAVE);
      xy_b_motor->onestep(BACKWARD, INTERLEAVE);
      _xy_last_step = millis();
      _y_pos++;
    }
    else if((_x_target-_x_pos)==0 && (_y_target-_y_pos)<0){
      //Move down
      xy_a_motor->onestep(BACKWARD, INTERLEAVE);
      xy_b_motor->onestep(FORWARD, INTERLEAVE);
      _xy_last_step = millis();
      _y_pos--;
    }
    else if((_x_target-_x_pos)>0 && (_y_target-_y_pos)==0){
      //Move right
      xy_a_motor->onestep(FORWARD, INTERLEAVE);
      xy_b_motor->onestep(FORWARD, INTERLEAVE);
      _xy_last_step = millis();
      _x_pos++;
    }
    else if((_x_target-_x_pos)<0 && (_y_target-_y_pos)==0){
      //Move left
      xy_a_motor->onestep(BACKWARD, INTERLEAVE);
      xy_b_motor->onestep(BACKWARD, INTERLEAVE);
      _xy_last_step = millis();
      _x_pos--;
    }

  }


}
开发者ID:Durermf,项目名称:Microscope,代码行数:93,代码来源:Stage.cpp


示例19: setup

void setup(){
	Serial.begin(B2_SERIAL0_BOUND);
	serial0Buffer = "";
	Serial.println("");	// remove dust
	Serial.flush();

	// read pcb type	
	pinMode( PIN_B3_POWER_SENSOR, INPUT );
	boolean power = digitalRead( PIN_B3_POWER_SENSOR );
	if( power == LOW ){
		Serial.println("-chyba 2");
	}else{
		Serial.println("-chyba 3");
	}

	//pcb_type
	disableYZ();
	if(pcb_type == 2 ){		// servos + magicled
		//pinMode(PIN_B2_SERVO_Y, INPUT+INPUT_PULLUP );      // nie pozwalaj na przypadkowe machanie na starcie
		//pinMode(PIN_B2_SERVO_Z, INPUT+INPUT_PULLUP );      // nie pozwalaj na przypadkowe machanie na starcie
		pinMode(PIN_B2_SELF_RESET, INPUT );	
		pinMode(PIN_B2_HALL_X, INPUT + INPUT_PULLUP );
		pinMode(PIN_B2_HALL_Y, INPUT + INPUT_PULLUP );
		pinMode(PIN_B2_WEIGHT, INPUT);

	}else if(pcb_type == 3 ){		// actuators + magicled
		if(YZ_INPUT_ON_DISABLE){
			pinMode(PIN_B3_OUT_Y1, INPUT );		// stop Y
			pinMode(PIN_B3_OUT_Y2, INPUT );		// stop Y		
			pinMode(PIN_B3_OUT_Z1, INPUT );		// stop Z	
			pinMode(PIN_B3_OUT_Z2, INPUT );		// stop Z
		}else{
			pinMode(PIN_B3_OUT_Y1, OUTPUT);
			pinMode(PIN_B3_OUT_Y2, OUTPUT);
			pinMode(PIN_B3_OUT_Z1, OUTPUT);
			pinMode(PIN_B3_OUT_Z2, OUTPUT);
			pinMode(PIN_B3_LIGHT, INPUT );

			digitalWrite(PIN_B3_OUT_Y1, YZ_VALUE_ON_DISABLE);		// stop Y
			digitalWrite(PIN_B3_OUT_Y2, YZ_VALUE_ON_DISABLE);
			digitalWrite(PIN_B3_OUT_Z1, YZ_VALUE_ON_DISABLE);		// stop Z
			digitalWrite(PIN_B3_OUT_Z2, YZ_VALUE_ON_DISABLE);	

		}
		//pinMode(PIN_B3_POWER_SENSOR, INPUT + INPUT_PULLUP );
		pinMode(PIN_B3_POWER_SENSOR, INPUT );	
	}

	// blink led	
	pinMode(PIN_B2_STEPPER_DIR, OUTPUT );
	for(byte i =0; i<pcb_type;i++){
		digitalWrite( PIN_B2_STEPPER_DIR, HIGH );
		delay(100);
		digitalWrite( PIN_B2_STEPPER_DIR, LOW );
		delay(200);
	}
	init_leds();
	setupStepper();

	unsigned long int color = bottom_panels.Color(0,  0,  20 );	
	set_all_leds(color);
	Serial.println("");	// remove dust
	Serial.flush();
	Serial.println("BSTART");

	if(pcb_type == 2 ){		// servos + magicled
		init_hallx(PIN_B2_HALL_X);
	}else if(pcb_type == 3 ){
		init_hallx(PIN_B3_IN_X);
	}

	sendStats( true );
	Serial.flush();
}
开发者ID:ArturFormella,项目名称:barobot,代码行数:74,代码来源:barobot_carret2.cpp


示例20: getBackButton

// Buttons
//////////
boolean Reflowster::getBackButton() {
  return !digitalRead(pinConfiguration_backButton);
}
开发者ID:julianh2o,项目名称:Reflow-Controller,代码行数:5,代码来源:Reflowster.cpp



注:本文中的digitalRead函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ digitalWrite函数代码示例发布时间:2022-05-30
下一篇:
C++ digitalPinToPort函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap