Skip to content

Instantly share code, notes, and snippets.

@clarkbw
Created November 10, 2014 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkbw/ef1adef9f79d8409ca83 to your computer and use it in GitHub Desktop.
Save clarkbw/ef1adef9f79d8409ca83 to your computer and use it in GitHub Desktop.
/*
Copyright (c) 2012-2014 RedBearLab
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Chat
*
* Simple chat sketch, work with the Chat iOS/Android App.
* Type something from the Arduino serial monitor to send
* to the Chat App or vice verse.
*
*/
//"services.h/spi.h/boards.h" is needed in every new project
#include <SPI.h>
#include <boards.h>
#include <RBL_nRF8001.h>
#include <services.h>
// isdigit
#include <ctype.h>
// atoi
#include <unistd.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define I2C_ADDR 0x27
#define LED_OFF 0
#define LED_ON 1
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
lcd.begin(16,2); // initialize the lcd
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(LED_ON);
lcd.home (); // go home
lcd.print("Hello, ARDUINO ");
lcd.setCursor ( 0, 1 ); // go to the next line
lcd.print (" WORLD!");
// Default pins set to 9 and 8 for REQN and RDYN
// Set your REQN and RDYN here before ble_begin() if you need
//ble_set_pins(3, 2);
// Set your BLE Shield name here, max. length 10
ble_set_name("LittleBear");
// Init. and start BLE library.
ble_begin();
// Enable serial debug
Serial.begin(57600);
delay(1000);
lcd.clear();
// lcd.autoscroll();
}
const int MAX_BUF = 64;
unsigned char buf[MAX_BUF] = {0};
unsigned char len = 0;
void loop()
{
if ( ble_available() )
{
lcd.clear();
// write previous message
lcd.setCursor ( 0, 0 ); // go to home
for (int i = 0; i < len; i++) {
lcd.write(buf[i]);
}
len = 0;
lcd.setCursor ( 0, 1 ); // go to the next line
while ( ble_available() ) {
byte data = ble_read();
buf[len++] = data;
if (-1 != data) {
lcd.write (data);
}
}
buf[len++] = ' ';
}
if ( Serial.available() )
{
delay(5);
while ( Serial.available() )
ble_write( Serial.read() );
}
ble_do_events();
}
@clarkbw
Copy link
Author

clarkbw commented Nov 10, 2014

SLC: A5
SDA: A4
VCC: 5V
GND: GND

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment