void mcu_main() { int version = api_version(); debug_print(DBG_INFO, "API version: %d.%d\n", version/100, version%100); gpio_setup(GPIO_DHT, OUTPUT); gpio_write(GPIO_DHT, HIGH); /* do not send instructions within 1S after power on to pass the unstable state */ mcu_sleep(100); uint8_t data[DHT_DATA_LEN]; while (1) { int rc; uint8_t humidity, temperature; if ((rc = dht11_read(GPIO_DHT, data, sizeof(data))) == DHT_SUCCESS) { humidity = data[0], temperature = data[2]; debug_print(DBG_INFO, "Humidity: %d%, Temperature: %d C\n", humidity, temperature); // debug_print(DBG_INFO, "%d %d %d %d %d\n", // data[0], data[1], data[2], data[3], data[4]); } else { debug_print(DBG_ERROR, "dht11_read() error [%d]\n", rc); } unsigned char buf[LEN_IPCBUF]; if ((rc = host_receive(buf, sizeof(buf))) > 0 && buf[0] == '?') { rc = mcu_snprintf((char*)buf, LEN_IPCBUF, "RH=%d,T=%d\n", humidity, temperature); host_send(buf, rc); } mcu_sleep(300); } }
void mcu_main() { // by default, the edison has ID 0 int edisonID = 0; // if we pass in an argument, use it for the edisonID // please pass in an integer //if (argc == 2) { //edisonID = atoi(argv[1]); //} int temp; while (1) { //int host_receive(unsigned char *buf, int length) temp = host_receive((unsigned char *)host_message, BUFFER_LENGTH); if (temp > 0) { debug_print(DBG_INFO, "Received a Message!\n"); host_send((unsigned char*)"hello mcu\n", 10); preamble_length = host_message[0]; } // Preamble - Signals the Receiver Message Incoming send_preamble_sequence(preamble_length); // Sending Edison Board ID # - 2 bits, MSB then LSB switch (edisonID) { case 0: send_low_bit(); // Send lsb bit 0 = LOW send_low_bit(); // Send msb bit 1 = LOW break; case 1: send_high_bit(); // Send lsb bit 0 = HIGH send_low_bit(); // Send msb bit 1 = LOW break; case 2: send_low_bit(); // Send lsb bit 0 = LOW send_high_bit(); // Send msb bit 1 = break; case 3: send_high_bit(); // Send lsb bit 0 = HIGH send_high_bit(); // Send msb bit 1 = HIGH break; default: send_low_bit(); // Send lsb bit 0 = LOW send_low_bit(); // Send msb bit 1 = LOW } // Sending Edison IR Emitter ID # - 2 bits, MSB then LSB // pwm1 = 00 = short-long/short-long = 5-20/5-20 // pwm2 = 01 = short-long/long-short = 5-20/20-5 // pwm3 = 10 = long-short/short-long = 20-5/5-20 // pwm4 = 11 = long-short/long-short = 20-5/20-5 // First Bit pwm_configure(pwm1, MESSAGE_DUTY_LOW, MESSAGE_PERIOD); // 0 pwm_configure(pwm2, MESSAGE_DUTY_LOW, MESSAGE_PERIOD); // 0 pwm_configure(pwm3, MESSAGE_DUTY_HIGH, MESSAGE_PERIOD); // 1 pwm_configure(pwm4, MESSAGE_DUTY_HIGH, MESSAGE_PERIOD); // 1 pwm_enable(pwm1); pwm_enable(pwm2); pwm_enable(pwm3); pwm_enable(pwm4); mcu_delay(MESSAGE_SLEEP); // Second Bit pwm_configure(pwm1, MESSAGE_DUTY_LOW, MESSAGE_PERIOD); // 0 pwm_configure(pwm2, MESSAGE_DUTY_HIGH, MESSAGE_PERIOD); // 1 pwm_configure(pwm3, MESSAGE_DUTY_LOW, MESSAGE_PERIOD); // 0 pwm_configure(pwm4, MESSAGE_DUTY_HIGH, MESSAGE_PERIOD); // 1 pwm_enable(pwm1); pwm_enable(pwm2); pwm_enable(pwm3); pwm_enable(pwm4); mcu_delay(MESSAGE_SLEEP); } }
void mcu_main() { gpio_setup(13, 1); // pin 5 = right gpio_setup(182, 1); // pin 6 = down gpio_setup(48, 1); // pin 7 = right gpio_setup(49, 1); // pin 8 = up char buf[64]; int len; while (1) { do { len = host_receive((unsigned char *)buf, 64); //mcu_sleep(10); } while (len <= 0); if (strcmp(buf, "") != 0) { /* * buf = string of 4 bits ie, "0101" * big endian, bit 0 = up, bit 1 = left, bit 2 = down, bit 3 = right * 1 = on, 0 = off */ int up = (int)buf[0] - 48; int left = (int)buf[1] - 48; int down = (int)buf[2] - 48; int right = (int)buf[3] - 48; if(up == 1) { gpio_write(49, 1); } if (up == 0) { gpio_write(49, 0); } if(right == 1) { gpio_write(13, 1); } if(right == 0) { gpio_write(13, 0); } if(down == 1) { gpio_write(182, 1); } if(down == 0) { gpio_write(182, 0); } if(left == 1) { gpio_write(48, 1); } if(left == 0) { gpio_write(48, 0); } //Alternate method, may be faster /* int direction; switch (direction) { case(1) : gpio_write(49, 1); break; case(2) : gpio_write(13, 1); break; case(3) : gpio_write(182, 1); break; case(4) : gpio_write(48, 1); break; } */ } } }