Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <MemoryFree.h>
- #include <SPI.h>
- #include "Adafruit_BLE_UART.h"
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- // Connect CLK/MISO/MOSI to hardware SPI
- // e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
- #define ADAFRUITBLE_REQ 10
- #define ADAFRUITBLE_RDY 2 // This should be an interrupt pin, on Uno thats #2 or #3
- #define ADAFRUITBLE_RST 9
- Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
- /**************************************************************************/
- /*!
- Configure the Arduino and start advertising with the radio
- */
- /**************************************************************************/
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- long ArrayC[20] ;
- String inputString;
- String overString;
- String Stringa[10];
- int LunghezzaStringa ;
- unsigned long previousMillis = 0;
- int Nstring;
- int *v;
- void setup() {
- Serial.begin(115200);
- for (int i = 0; i < 20; i++)
- ArrayC[i] = 0;
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 1);
- lcd.clear();
- BTLEserial.setDeviceName("MARCO"); /* 7 characters max! */
- BTLEserial.begin();
- }
- aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;
- void loop() {
- unsigned long currentMillis = millis();
- BTLEserial.pollACI();
- aci_evt_opcode_t status = BTLEserial.getState();
- if (status != laststatus) {
- // print it out!
- if (status == ACI_EVT_DEVICE_STARTED) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(F("In Attesa di"));
- lcd.setCursor(0, 1);
- lcd.print(F("Una Connessione"));
- }
- if (status == ACI_EVT_CONNECTED) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(F("Connesso!"));
- }
- if (status == ACI_EVT_DISCONNECTED) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(F("Disconnesso"));
- }
- // OK set the last status change to this one
- laststatus = status;
- }
- if (status == ACI_EVT_CONNECTED) {
- // Serial.print("freeMemory()=");
- // Serial.println(freeMemory());
- // Lets see if there's any data for us!
- if (BTLEserial.available()) {
- Nstring++;
- if (Nstring == 1)
- for (int i = 0; i < 10; i++)
- Stringa[i] = "";
- previousMillis = currentMillis;
- lcd.clear();
- lcd.print(freeMemory());
- Serial.print("* "); Serial.print(BTLEserial.available()); Serial.println(F(" bytes available from BTLE"));
- }
- // OK while we still have something to read, get a character and print it out
- int it = 0;
- while (BTLEserial.available()) {
- int c = BTLEserial.read();
- ArrayC[it] = c;
- inputString += char(c);
- it++;
- }
- overString += inputString;
- inputString = "";
- if (currentMillis - previousMillis >= 250) {
- previousMillis = currentMillis;
- Nstring = 0;
- if (overString.length() > 0) {
- Serial.println(overString);
- Taglio(overString);
- for (int i = 0; i < 10; i++)
- Serial.println(Stringa[i]);
- overString = "";
- }
- }
- }
- }
- void Taglio(String Iniziale)
- {
- free(v);
- Iniziale.reserve(100);
- Stringa[0] = Iniziale;
- for (int i = 0; i < 10; i++)
- {
- // v = (int*) malloc(sizeof(Stringa[i])) ;
- if (Stringa[i].length() > 16) {
- Iniziale = Stringa[i];
- int StartLength = Iniziale.length();
- Stringa[i] = Iniziale.substring(0, 16);
- int LastSpace = Stringa[i].lastIndexOf(" ");
- Stringa[i + 1] = Iniziale.substring( LastSpace + 1, StartLength );
- Stringa[i] = Iniziale.substring(0, LastSpace);
- }
- }
- }
- /*
- int StartLength = Iniziale.length();
- if (StartLength > 16) {
- Stringa[0] = Iniziale.substring(0, 16);
- int LastSpace = Stringa[0].lastIndexOf(" ");
- Stringa[1] = Iniziale.substring( LastSpace + 1, StartLength );
- Stringa[0] = Iniziale.substring(0, LastSpace);
- if (Stringa[1].length() > 16) {
- Iniziale = Stringa[1];
- StartLength = Iniziale.length();
- Stringa[1] = Iniziale.substring(0, 16);
- LastSpace = Stringa[1].lastIndexOf(" ");
- Stringa[2] = Iniziale.substring( LastSpace + 1, StartLength );
- Stringa[1] = Iniziale.substring(0, LastSpace);
- if (Stringa[2].length() > 16) {
- Iniziale = Stringa[2];
- StartLength = Iniziale.length();
- Stringa[2] = Iniziale.substring(0, 16);
- LastSpace = Stringa[2].lastIndexOf(" ");
- Stringa[3] = Iniziale.substring( LastSpace + 1, StartLength );
- Stringa[2] = Iniziale.substring(0, LastSpace);
- }
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement