Permalink
Browse files

Bug fixes in Bluetooth patches, new Bluetooth Connection patch, new B…

…T examples
  • Loading branch information...
Marco Triverio
Marco Triverio committed Apr 7, 2015
1 parent 8cbdf07 commit 9e5b1f5ce345e5a40792eab6f2acbed23e04b974
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>BuildMachineOSBuild</key>
+ <string>14C1514</string>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>Bluetooth Connection</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.ideo.Bluetooth-Connection</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>Bluetooth Connection</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>DTCompiler</key>
+ <string>com.apple.compilers.llvm.clang.1_0</string>
+ <key>DTPlatformBuild</key>
+ <string>6C131e</string>
+ <key>DTPlatformVersion</key>
+ <string>GM</string>
+ <key>DTSDKBuild</key>
+ <string>14A383</string>
+ <key>DTSDKName</key>
+ <string>macosx10.10</string>
+ <key>DTXcode</key>
+ <string>0620</string>
+ <key>DTXcodeBuild</key>
+ <string>6C131e</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright © 2015 Marco Triverio. All rights reserved.</string>
+ <key>QCPlugInClasses</key>
+ <array>
+ <string>Bluetooth_ConnectionPlugIn</string>
+ </array>
+</dict>
+</plist>
@@ -0,0 +1,120 @@
+/*
+
+Avocado + Arduino
+Created by: Marco Triverio
+
+INSTRUCTIONS
+Follow this tutorial to have your Blend Micro work with the Arduino IDE
+http://redbearlab.com/getting-started-blendmicro
+In Quartz Composer user Bluetooth Send, Bluetooth Receive, and Aggregate Values to communicate with your Blend Micro
+
+*/
+
+
+#include <SPI.h>
+#include <boards.h>
+#include <RBL_nRF8001.h>
+
+#define DIGITAL_OUT_PIN 13
+#define DIGITAL_IN_PIN 9
+
+// Received data
+// - data_buffer gives access to the 4 bytes that have been received
+// - data aggregates those 4 bytes in one unsigned long
+byte data_buffer[4] = { 0x00, 0x00, 0x00, 0x00 };
+unsigned long data = 0;
+
+void setup()
+{
+ // Set your BLE Shield name here, max. length 10
+ ble_set_name("BlendMicro");
+
+ // Init. and start BLE library.
+ ble_begin();
+
+ // Set pin mode
+ pinMode(DIGITAL_OUT_PIN, OUTPUT);
+ pinMode(DIGITAL_IN_PIN, INPUT);
+
+ // Enable serial debug
+ Serial.begin(57600);
+ Serial.println("Ready to communicate with Avocado!");
+}
+
+
+void loop()
+{
+ // If data is ready
+ while(ble_available())
+ {
+ // receives values and stores them in data_buffer and data
+ readBluetoothData();
+
+ // use the received value (0-255) to change intensity of LED
+ analogWrite(DIGITAL_OUT_PIN, data_buffer[3]);
+ }
+
+ if (!ble_connected())
+ {
+ digitalWrite(DIGITAL_OUT_PIN, LOW);
+ }
+
+ uint8_t input = digitalRead(DIGITAL_IN_PIN);
+ writeData(0,0,0,input);
+
+ // Allow BLE Shield to send/receive data
+ ble_do_events();
+
+ // Waits before sending something else
+ delay(200);
+}
+
+
+void writeData(uint8_t data0, uint8_t data1, uint8_t data2, uint8_t data3) {
+ Serial.print("Sending ");
+ Serial.print(data0);
+ Serial.print(", ");
+ Serial.print(data1);
+ Serial.print(", ");
+ Serial.print(data2);
+ Serial.print(", ");
+ Serial.println(data3);
+
+ ble_write(data0);
+ ble_write(data1);
+ ble_write(data2);
+ ble_write(data3);
+}
+
+void readBluetoothData() {
+ Serial.print("\nJust received bytes ");
+ data = 0;
+ for(int i=0; i<4; i++) {
+
+ // read values sent via bluetooth
+ data_buffer[i] = ble_read();
+
+ // print values as they come in
+ print_debug(data_buffer[i], i);
+
+ // aggregate values into one
+ // (useful when trying to send values greater than 255)
+ data += ((unsigned long)data_buffer[i] << (3-i)*8);
+ }
+
+ Serial.print("Aggregated value: ");
+ Serial.println((unsigned long)data);
+}
+
+void print_debug(unsigned int data, int i) {
+ Serial.print("[");
+ Serial.print(i);
+ Serial.print("] ");
+ Serial.print(data);
+
+ if (i<3) Serial.print(", ");
+ else Serial.println();
+}
+
+
+
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 9e5b1f5

Please sign in to comment.