int producerth2(void){ int count = 0; int flag=0; iolib_setdir(8,12, BBBIO_DIR_IN); /* Set pin P8 - 11 as input */ while(count < 10) { char l='R'; iolib_delay_ms(100); if (is_high(8,12)) /* Check if in is high (i.e. button pressed) */ { if (flag==1) { flag=0; enqueue(l,count+10); count++; continue; } else continue; } if (is_low(8,12)) /* Check if in is low (i.e button is released) */ { if (flag==0) { flag=1; } else continue; } } return 0; }
int main(void) { int del; iolib_init(); /* Initialize I/O library - required */ iolib_setdir(8,11, BBBIO_DIR_IN); /* Set pin P8 - 11 as input */ iolib_setdir(8,12, BBBIO_DIR_OUT); /* Set pin P8 - 12 as output */ int count = 0; while(count < 50) { count ++ ; if (is_high(8,11)) /* Check if in is high (i.e. button pressed) */ { del=100; /* fast speed */ } if (is_low(8,11)) /* Check if in is low (i.e button is released) */ { del=500; /* slow speed */ } pin_high(8,12); /* Set pin to high - LED on */ iolib_delay_ms(del); /* Delay for 'del' msec */ pin_low(8,12); /* Set pin to low - LED off */ iolib_delay_ms(del); /* Delay for 'del' msec */ } iolib_free(); /* Release I/O library prior to program exit - required */ return(0); }
void NEXA::Receiver::recv(code_t& cmd) { uint32_t start, stop; int32_t bits = 0L; uint16_t us; uint16_t ix; do { // Wait for the start condition while (is_low()); stop = RTC::micros(); // Collect the samples; high followed by low pulse ix = 0; while (ix < IX_MAX) { // Capture length of high period start = stop; while (is_high()); stop = RTC::micros(); us = stop - start; if (us < LOW_THRESHOLD || us > HIGH_THRESHOLD) break; m_sample[ix & IX_MASK] = us; ix += 1; // Capture length of low period start = stop; while (is_low()); stop = RTC::micros(); us = stop - start; if (us < LOW_THRESHOLD || us > HIGH_THRESHOLD) break; m_sample[ix & IX_MASK] = us; ix += 1; // Decode every four samples to a code bit if ((ix & IX_MASK) == 0) { int8_t bit = decode_bit(); if (bit < 0) break; bits = (bits << 1) | bit; } } } while (ix != IX_MAX); m_code = bits; cmd = bits; }
int my_str_isupper(char *str) { int i; i = 0;; if (str[i] == 0) { return (1); } while (str[i] != 0) { if (!is_low(str[i])) { return (0); } i = i + 1; } return (1); }
static bool is_same_range(u16 num1, u16 num2) { return is_high(num1) ? is_high(num2) : is_low(num2); }
static bool is_high(u16 num) { return !is_low(num); }