int main(){ time_t mytime; printf("Start at "); mytime = time(NULL); printf(ctime(&mytime), "\n\n"); // Чисто отладочная запись в консоль, когда была запущена программа bcm2835_close(); // Это надо на всякий случай ибо процесс прекращается по ctrl+c и до этой функции дело не доходит if (!bcm2835_init()) // Инициализация GPIO и выход с кодом "1" при неудаче return 1; bcm2835_gpio_set_pud(PIR_SIGNAL, BCM2835_GPIO_PUD_DOWN); // Подтяжка ножки к нулю bcm2835_gpio_fsel(PIR_SIGNAL, BCM2835_GPIO_FSEL_INPT); // Установка ножки для PIR на прием //printf("%u\n", bcm2835_gpio_lev(PIR_SIGNAL)); // Вывод значения ножки /////////Начало цикла слежения///////// while (1) { // Бесконечный цикл... Надо почитать про прерывания... while(!bcm2835_gpio_lev(PIR_SIGNAL)) {/* Ждем первого срабатывания */} time_to_file_first(); // см. выше printf("PIR activated at "); mytime = time(NULL); printf(ctime(&mytime), "\n\n"); // То было в файл, а это в консоль // Пауза в мс. Аналог чувствительности датчика. Нужна чтобы отсечь ложные срабатывания bcm2835_delay(2000); // Проверяем сигнал после паузы (PIR либо потухнет, либо останется активен) // Если сигнал остался, то в консоль выводим время и ждем пока на ножке не появится ноль if(bcm2835_gpio_lev(PIR_SIGNAL)) { printf("Movement detected at "); mytime = time(NULL); printf(ctime(&mytime), "\n"); //Вывод даты и времени time_to_file_on(); // А заодно и в файл while (bcm2835_gpio_lev(PIR_SIGNAL)) {/* ждем пока сигнал не прекратится */} printf("Movement stopped at "); mytime = time(NULL); printf(ctime(&mytime), "\n"); printf("\n\n"); //Вывод даты и времени time_to_file_off(); // И опять в файл } } // До сюда обычно дело не доходит. Но пусть пока останется. printf("End\n"); return (bcm2835_close()); }
int main(int argc, char *argv[]) { /* Declare Variables */ double syshz = 1000000; double systimestart = 0; double systimeend = 0; double elapsed_time = 0; /* Initialize bcm2835 library and check for errors */ if(!bcm2835_init()){ perror("bcm2835"); exit(EXIT_FAILURE); } /* get system time * sleep for 1 second * get system time after sleep * calculate difference of system time in seconds */ systimestart = (double) bcm2835_st_read(); sleep(1); systimeend = (double) bcm2835_st_read(); elapsed_time = (systimeend - systimestart)/syshz; printf("Sleep(1) elapsed time: %f seconds\n",elapsed_time); /* Close the library deallocating any allocated memory */ bcm2835_close(); return EXIT_SUCCESS; }
/********************************************************************* Main Program Loop **********************************************************************/ int main() { /* Initializations */ debug_init(); /* This should be first. */ timer_init(); /* This should be before any GPIO activities. */ uint32 ret_val = bcm2835_init(); if ( ret_val == 0 ) { DEBUG_MSG_ERROR("bcm2835_init() failed."); } pwm_init(); pump_init(); therm_init(); pid_init(); pump_start(); /* Take temperature as input from console. */ float setpoint; printf("Set your desired temperature: "); scanf("%f", &setpoint); pid_update_temp_setpoint(setpoint); pid_gain_params pid_gain; pid_gain.k_p = 1; pid_gain.k_d = 1; pid_gain.k_i = 1; pid_gain.k_windup = 1; pid_set_gain(&pid_gain); /* Main Program Loop */ while (1) { pwm_run(); therm_capture(); pid_loop(); } pump_stop(); /* De-initializations */ pump_deinit(); pid_deinit(); pwm_deinit(); /* This should be after all GPIO activities. */ ret_val = bcm2835_close(); if ( ret_val == 0 ) { DEBUG_MSG_ERROR("bcm2835_close() failed."); } timer_deinit(); debug_deinit(); /* This should be last. */ return 0; }
int main(int argc, char **argv) { uint8_t value,i; if (!bcm2835_init()) return 1; for(i=0;i<5;i++) { bcm2835_gpio_fsel(KEY[i], BCM2835_GPIO_FSEL_INPT); bcm2835_gpio_set_pud(KEY[i], BCM2835_GPIO_PUD_UP); } while (1) { for(i=0;i<5;i++) { if(bcm2835_gpio_lev(KEY[i])==0) { printf("press the key: %d\n", i); delay(500); } } } bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (!bcm2835_init()) //Configure I2C pins { printf("BCM libray error.\n"); } unsigned char pval = 0; printf("GPIO read pin status.\r\n"); while (1) { pval = ReadPinStatus(MFP_PIN); printf("MFP pin level is %d\r\n",pval); delay_ms(1000); pval = ReadPinStatus(MPL_PIN); printf("MPL pin level is %d\r\n",pval); delay_ms(1000); pval = ReadPinStatus(LUX_PIN); printf("LUX pin level is %d\r\n",pval); delay_ms(1000); pval = ReadPinStatus(ALERT_PIN); printf("ALERT pin level is %d\r\n",pval); delay_ms(1000); pval = ReadPinStatus(LED_PIN); printf("LED pin level is %d\r\n",pval); delay_ms(1000); pval = ReadPinStatus(ACLM_PIN); printf("ACLM pin level is %d\r\n",pval); delay_ms(1000); } bcm2835_close(); return 0; }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) return 1; // Set RPI pin P1-15 to be an input bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT); // with a pullup bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP); // And a low detect enable bcm2835_gpio_len(PIN); while (1) { if (bcm2835_gpio_eds(PIN)) { // Now clear the eds flag by setting it to 1 bcm2835_gpio_set_eds(PIN); printf("low event detect for pin 15\n"); } // wait a bit delay(500); } bcm2835_close(); return 0; }
void clear_io() { #if 0 bcm2835_spi_end(); #endif bcm2835_close(); }
int main() { BSP_Config_HW (); uint8_t data1[1],i=0; uint16_t j=0; uint8_t err=1, error=1; uint8_t data_seri[12]; NEXT_MODULE_t* Module; unlink("image.txt"); unlink("image.JPG"); while(1) { error = NEXT_Module_FingerPresent(Module, data1,0x01); printf("Dat ngon tay vao cam bien\n"); BSP_Delay_ms(1000); if (data1[0] < 50) continue; error = NEXT_Module_ScanImage(Module); printf("Da quet dau van tay thanh cong\n"); BSP_Module_Reset_Configure(); break; } bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) return 1; // Set RPI pin P1-15 to be an input bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT); // with a pullup bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP); // Blink while (1) { // Read some data uint8_t value = bcm2835_gpio_lev(PIN); printf("read from pin 15: %d\n", value); // wait a bit delay(500); } bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (!bcm2835_init()) { printf("bcm2835 init failed\n"); return 1; } // Set the output pin to Alt Fun 5, to allow PWM channel 0 to be output there bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_ALT5); bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_2); bcm2835_pwm_set_mode(PWM0, 1, 1); bcm2835_pwm_set_range(PWM0, RANGE); bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_ALT5); bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_4); bcm2835_pwm_set_mode(PWM1, 1, 1); bcm2835_pwm_set_range(PWM1, RANGE*2); bcm2835_pwm_set_data(PWM0, 1); bcm2835_pwm_set_data(PWM1, 1); while(1) { } bcm2835_close(); return 0; }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) return 1; // Set the pin to be an output bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP); // Blink while (1) { // Turn it on bcm2835_gpio_write(PIN, HIGH); bcm2835_gpio_write(PIN, HIGH); bcm2835_gpio_write(PIN, HIGH); // wait a bit // bcm2835_delay(500); // turn it off bcm2835_gpio_write(PIN, LOW); bcm2835_gpio_write(PIN, LOW); bcm2835_gpio_write(PIN, LOW); // wait a bit // bcm2835_delay(500); } bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (!bcm2835_init()) return 1; bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_INPT); bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_INPT); bcm2835_gpio_set_pud(PIN0, BCM2835_GPIO_PUD_UP); bcm2835_gpio_set_pud(PIN1, BCM2835_GPIO_PUD_UP); bcm2835_gpio_fsel(POUT1, BCM2835_GPIO_FSEL_ALT5); bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_256); bcm2835_pwm_set_mode(0, 1, 1); bcm2835_pwm_set_range(0, 1024); int data=0; while (1) { uint8_t in0 = bcm2835_gpio_lev(PIN0); uint8_t in1 = bcm2835_gpio_lev(PIN1); if (in1 == 0) break; data ++; if(data > 1023) data=0; bcm2835_pwm_set_data(0, data); bcm2835_delay(2); } bcm2835_pwm_set_data(0, 0); bcm2835_gpio_fsel(POUT1, BCM2835_GPIO_FSEL_INPT); bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (argc == 1) { return 1; } if (!bcm2835_init()) { fprintf(stderr, "Failed to initialize bcm2835\n"); return 1; } bcm2835_gpio_fsel(IRIS_PIN, BCM2835_GPIO_FSEL_OUTP); char arg = *argv[1]; switch (arg) { case 'o': printf("IRIS - open\n"); bcm2835_gpio_write(IRIS_PIN, LOW); break; case 'c': printf("IRIS - close\n"); bcm2835_gpio_write(IRIS_PIN, HIGH); break; default: break; } bcm2835_close(); return 0; }
static PyObject * PyBCM2835_close(PyObject *self) { int rtn = bcm2835_close(); return Py_BuildValue("i",rtn); }
void close_sockets() { if (mux >= 0) close(mux); bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_INPT); bcm2835_close(); }
int main(int argc, char **argv) { if (!bcm2835_init()) { return 1; } bcm2835_gpio_fsel(LED_PIN, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(BUZ_PIN, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(TLT_PIN, BCM2835_GPIO_FSEL_INPT); bcm2835_gpio_set_pud(TLT_PIN, BCM2835_GPIO_PUD_DOWN); for (int i = 0; i < 100; i++) { uint8_t value = bcm2835_gpio_lev(TLT_PIN); printf("read from pin %d : %d\n", TLT_PIN, value); if (value == 0) { bcm2835_gpio_write(LED_PIN, HIGH); bcm2835_gpio_write(BUZ_PIN, LOW); } else { bcm2835_gpio_write(LED_PIN, LOW); bcm2835_gpio_write(BUZ_PIN, HIGH); } bcm2835_delay(500); } bcm2835_gpio_write(LED_PIN, LOW); bcm2835_close(); return 0; }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO if (!bcm2835_init()) return 1; // Set RPI pin to be an input bcm2835_gpio_fsel(RF_IRQ_PIN, BCM2835_GPIO_FSEL_INPT); // with a puldown bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN); // And a rising edge detect enable bcm2835_gpio_ren(RF_IRQ_PIN); while (1) { // we got it ? if (bcm2835_gpio_eds(RF_IRQ_PIN)) { // Now clear the eds flag by setting it to 1 bcm2835_gpio_set_eds(RF_IRQ_PIN); printf("Rising event detect for pin GPIO%d\n", RF_IRQ_PIN); } // wait a bit bcm2835_delay(5); } bcm2835_close(); return 0; }
int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) { return 1; } bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default int i; for( i = 0; i < 100; i++ ) { // Send a byte to the slave and simultaneously read a byte back from the slave // If you tie MISO to MOSI, you should read back what was sent uint8_t data = bcm2835_spi_transfer(i); printf("Wrote: %02X Read from SPI: %02X\n", i, data); } bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (!bcm2835_init()) return 1; bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE1); bcm2835_spi_setClockDivider(2170-200); bcm2835_spi_chipSelect(BCM2835_SPI_CS0); bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4; bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_LEN, BCM2835_SPI0_CS_LEN); //make it 9 bit volatile uint32_t* ltoh = bcm2835_spi0+BCM2835_SPI0_LTOH/4; bcm2835_peri_set_bits(ltoh,0b1111,0); unsigned int i='a'; while(1) { for(char c='a';c<='z';c++) { spi_uart_tx(c); spi_uart_tx(' '); } spi_uart_tx('\n'); // bcm2835_delay(10); // printf(" "); } bcm2835_spi_end(); bcm2835_close(); return 0; }
//int bcm2835_close(void); /// Call bcm2835_close() and set ope_code & return code into local buff /// \par Refer /// \par Modify /// \return done:0, time_over:-1 void bcm_close(void) { set_ope_code( OPE_CLOSE ); set_int_code( bcm2835_close() ); put_reply(); mark_sync(); }
GPIO::~GPIO() { #ifdef DEBUG std::cout << "GPIO: Destructor called." << std::endl; #endif bcm2835_close(); isBCM2835Initialized = false; }
/** * Main. * * @param int argc * @param char** argv * * @return int */ int main(int argc, char **argv) { bcm2835_set_debug(0); if (!bcm2835_init()) { return 1; } // Set each of the pins as input or output bcm2835_gpio_fsel(NES_LATCH,BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(NES_CLOCK,BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(NES_DATA,BCM2835_GPIO_FSEL_INPT); // Initialize clock and latch bcm2835_gpio_write(NES_LATCH,LOW); bcm2835_gpio_write(NES_CLOCK,LOW); while(1) { uint8_t pressed = read_buttons(); if ((pressed & BTN_A) == BTN_A) printf("A"); if ((pressed & BTN_B) == BTN_B) printf("B"); if ((pressed & BTN_SELECT) == BTN_SELECT) printf("SELECT"); if ((pressed & BTN_START) == BTN_START) printf("START"); if ((pressed & BTN_UP) == BTN_UP) printf("UP"); if ((pressed & BTN_DOWN) == BTN_DOWN) printf("DOWN"); if ((pressed & BTN_LEFT) == BTN_LEFT) printf("LEFT"); if ((pressed & BTN_RIGHT) == BTN_RIGHT) printf("RIGHT"); if (pressed) { printf("\n"); } // Delay approximately 60Hz delay(((1 / 60) * 1000)); } bcm2835_close(); return 0; }
int drvGPIO_stop(void) { if (sInstDscr.started) { bcm2835_close(); sInstDscr.started = FALSE; } return R_SUCCESS; }
int main(int argc, char **argv) { printf("Running ... \n"); // parse the command line if (comparse(argc, argv) == EXIT_FAILURE) return showusage (EXIT_FAILURE); if (!bcm2835_init()) { printf("bcm2835_init failed. Are you running as root??\n"); return 1; } // I2C begin if specified if (init == I2C_BEGIN) { if (!bcm2835_i2c_begin()) { printf("bcm2835_i2c_begin failed. Are you running as root??\n"); return 1; } } // If len is 0, no need to continue, but do I2C end if specified if (len == 0) { if (init == I2C_END) bcm2835_i2c_end(); printf("... done!\n"); return EXIT_SUCCESS; } bcm2835_i2c_setSlaveAddress(slave_address); bcm2835_i2c_setClockDivider(clk_div); fprintf(stderr, "Clock divider set to: %d\n", clk_div); fprintf(stderr, "len set to: %d\n", len); fprintf(stderr, "Slave address set to: %d\n", slave_address); if (mode == MODE_READ) { for (i=0; i<MAX_LEN; i++) buf[i] = 'n'; data = bcm2835_i2c_read(buf, len); printf("Read Result = %d\n", data); for (i=0; i<MAX_LEN; i++) { if(buf[i] != 'n') printf("Read Buf[%d] = %x\n", i, buf[i]); } } if (mode == MODE_WRITE) { data = bcm2835_i2c_write(wbuf, len); printf("Write Result = %d\n", data); } // This I2C end is done after a transfer if specified if (init == I2C_END) bcm2835_i2c_end(); bcm2835_close(); printf("... done!\n"); return 0; }
int main(int argc, char **argv) { PiSwitchConfig config; if(!TryGetPiSwitchConfig(CONFIG_FILE, argc, argv, &config)) { fprintf(stderr, "Configuration error\n"); return -1; } // Open the log file openlog(LOG_IDENTITY, LOG_PID, config.RunAsDaemon ? LOG_DAEMON : LOG_USER); syslog(LOG_INFO, "Listening on gpio: %u, Writing to gpio: %u, Poll frequency: %u", config.GpioIn, config.GpioOut, config.PollFrequency); bcm2835_set_debug((uint8_t) config.DebugEnabled); running = true; TryStartDaemon(&config); SetupSignals(); SetupGpio(config.GpioIn, config.GpioOut); bool powerOff = false; while (running) { if(bcm2835_gpio_lev(config.GpioIn) == HIGH) { // Check it again! bcm2835_delay(500); if(bcm2835_gpio_lev(config.GpioIn) == HIGH) { powerOff = true; break; } } bcm2835_delay(config.PollFrequency); } if(powerOff) { syslog(LOG_INFO, "gpio %u set to HIGH, shutting system down", config.GpioIn); } else { syslog(LOG_INFO, "signal reveived, stopping"); } closelog(); bcm2835_close(); if(powerOff) { system("poweroff"); } TryStopDaemon(&config); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { bcm2835_init(); if(comparse(argc, argv) == EXIT_FAILURE) return 0; // setting PWM_PIN as pwm from channel 0 in markspace mode with range = RANGE bcm2835_gpio_fsel(PWM_PIN, BCM2835_GPIO_FSEL_ALT5); //ALT5 is pwm mode bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_16); // pwm freq = 19.2 / 16 MHz bcm2835_pwm_set_mode(PWM_CHANNEL, 1, 1); // markspace mode bcm2835_pwm_set_range(PWM_CHANNEL, RANGE); bcm2835_gpio_fsel(OE_SHIFTER, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_set_pud(OE_SHIFTER, BCM2835_GPIO_PUD_DOWN); //pull-down for output enable of logic shifters bcm2835_gpio_fsel(MOTOR_D3, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_set_pud(MOTOR_D3, BCM2835_GPIO_PUD_DOWN); //pull-down for motor enable bcm2835_gpio_fsel(PA0, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_set_pud(PA0, BCM2835_GPIO_PUD_UP); bcm2835_gpio_write(PA0, HIGH); bcm2835_gpio_write(OE_SHIFTER, HIGH); bcm2835_gpio_write(MOTOR_D3, LOW); // creating and running threads pthread_t th1, th2, th3, th4, th5, th6, th7; pthread_create(&th1, NULL, (void*)encoder_time_thread, NULL); pthread_create(&th2, NULL, (void*)magnet_time_thread, NULL); pthread_create(&th3, NULL, (void*)encoder_thread, NULL); pthread_create(&th4, NULL, (void*)magnet_thread, NULL); pthread_create(&th5, NULL, (void*)energy_time_thread, NULL); pthread_create(&th6, NULL, (void*)calculate_energy, NULL); pthread_create(&th7, NULL, (void*)calculate_I_ref, NULL); bcm2835_delay(100); // delay to make sure that all threads are initialised and iC-MU is conofigured printf("\nPress enter to start the motor."); getchar(); bcm2835_gpio_write(MOTOR_D3, HIGH); start = 1; printf("Started.\n"); printf("\nPress enter to stop the motor.\n"); getchar(); bcm2835_gpio_write(MOTOR_D3, LOW); bcm2835_spi_end(); bcm2835_close(); return 0; }
int main(int argc, char *argv[]) { if (!bcm2835_init()) { printf("Failed to init bcm2835\n"); return 1; } // Set the pin to be an output bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP); int rep; char *on_or_off = NULL; on_or_off = argv[1]; if (!(on_or_off)) { printf("Usage %s on|off \n",argv[0]); exit(2); } usleep(500); bcm2835_gpio_write(PIN, LOW); usleep(8000); for (rep=0; rep<10; rep++); //recall INVERSION out a 1 to ge a zero! { { bcm2835_gpio_write(PIN, LOW); usleep(8000); //above is gap between burst bgas_main(); //######################################################## if (strcmp(on_or_off,"on")==0){ bgas_on(); /* # It is on */ } else if (strcmp(on_or_off,"off") == 0) { bgas_off(); /* # It is off */ } // ################################################################## } // printf ("loop done\n"); } bcm2835_gpio_write(PIN, LOW); bcm2835_close(); return 0; } // main
int main(int argc, char **argv) { int first = 0x03, last = 0x77; int flags = 0; int version = 0; while (1 + flags < argc && argv[1 + flags][0] == '-') { switch (argv[1 + flags][1]) { case 'V': version = 1; break; case 'a': first = 0x00; last = 0x7F; break; default: fprintf(stderr, "Warning: Unsupported flag \"-%c\"!\n", argv[1 + flags][1]); //help(); // TODO exit(1); } flags++; } if (version) { fprintf(stderr, "i2cdetect version %s\n", VERSION); exit(0); } if (bcm2835_init() != 1) { fprintf(stderr, "bcm2835_init() failed\n"); exit(1); } bcm2835_i2c_begin(); bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_2500); // 100kHz int address; for (address = 0x00; address <= 0x7F; address++) { if (address < first || address > last) { continue; } bcm2835_i2c_setSlaveAddress(address); if (bcm2835_i2c_write(NULL, 0) == 0) { printf("0x%.2X : 0x%.2X : %s\n", address, address << 1, lookup_device(address)); } } bcm2835_i2c_end(); bcm2835_close(); return 0; }
int main(int argc, char **argv) { if (bcm2835_init() == 0) { return 1; } bcm2835_gpio_fsel(PIN37, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_write(PIN37, HIGH); bcm2835_close(); return 0; }
int prog_exit() { bcm2835_gpio_write(RELAY_INP1, HIGH); // turn off relay bcm2835_gpio_write(RELAY_INP2, HIGH); // 關閉 bcm2835 函式庫 if (!bcm2835_close()) { printf("Failed to close the library, deallocating any allocated memory and closing /dev/mem\n"); printf("\nPress any key to exit..."); return 2; } return 0; }