Paso 2: Programa Arduino
- Descargar e instalar el Arduino teensyduino
- Descargar esta biblioteca como un .zip haciendo clic en el botón "Descarga ZIP" en GitHub.
- En Arduino, cree un nuevo proyecto y vaya a "Bosquejo" -> "Incluir biblioteca" -> "agregar. Biblioteca ZIP..." Seleccionar el .zip que acabas de descargar.
- Crear un nuevo sketch de Arduino y coloque el código siguiente a él, seleccione el tipo de junta y descargar el código a la Junta
#include <ArduinoPebbleSerial.h> static const char* Button_Values[]= {"NONE","BACK", "UP", "SELECT", "DOWN"};static const uint16_t SUPPORTED_SERVICES[] = {0x0000, 0x1001}; static const uint8_t NUM_SERVICES = 2; static uint8_t pebble_buffer[GET_PAYLOAD_BUFFER_SIZE(200)]; static String pc_string;void setup() { // General init Serial.begin(115200); #if defined(__AVR_ATmega32U4__) ArduinoPebbleSerial::begin_hardware(pebble_buffer, sizeof(pebble_buffer), Baud57600, SUPPORTED_SERVICES, NUM_SERVICES); #else #error "This example will only work for those 32u4 based boards, e.g. Arduino Micro" #endif }void loop() { // Let the ArduinoPebbleSerial code do its processing size_t length; uint16_t service_id; uint16_t attribute_id; RequestType type; if (ArduinoPebbleSerial::feed(&service_id, &attribute_id, &length, &type)) { if ((service_id == 0x1001) && (attribute_id == 0x1001)) { // we have a raw data frame to process if (type == RequestTypeRead) {//Pebble want to read from Arduino // send a response to the Pebble - reuse the same buffer for the response uint32_t current_time = millis(); if(pc_string.length()==0){ pc_string = "EMPTY!!"; } char buf[50]; pc_string.toCharArray(buf, 50); Serial.print("pc_string.length()"); Serial.println(pc_string.length()); Serial.print("buf"); Serial.println(buf); memcpy(pebble_buffer, buf, pc_string.length()); pebble_buffer[pc_string.length()]='\0'; Serial.print("pebble_buffer"); Serial.println(pebble_buffer[0]); ArduinoPebbleSerial::write(true, pebble_buffer, pc_string.length()); Serial.print("Sent message to Pebble"); Serial.println(pc_string); pc_string = ""; } else if (type == RequestTypeWrite) {//Pebble wrote something to Arduino Serial.print("Got New Button event: "); uint8_t button_value = pebble_buffer[0]; uint8_t click_type = pebble_buffer[1]; if(button_value<=4){ Serial.println(Button_Values[button_value]); } } } else { // unsupported attribute - fail the request ArduinoPebbleSerial::write(false, NULL, 0); } } static bool is_connected = false; if (ArduinoPebbleSerial::is_connected()) { if (!is_connected) { Serial.println("Connected to the smartstrap!"); is_connected = true; } //scan the usb serial port for new input data if(Serial.available()){ char inChar = (char)Serial.read(); pc_string +=inChar; if(inChar=='#'){//stop sign Serial.println("Notifying Pebble: "); ArduinoPebbleSerial::notify(0x1001, 0x1001); } } } else { if (is_connected) { Serial.println("Disconnected from the smartstrap!"); is_connected = false; } } }