为了传说中的那啥, 啊, 嗯..

#include <CurieBLE.h>

const int ledPin = 13; // set ledPin to on-board LED  LED的pin脚就是14
const int buttonPin = 4; // set buttonPin to digital pin 4   按键pin脚是4

BLEPeripheral blePeripheral; // create peripheral instance    这里就好像一个起一个对象一样, 连new都不用, 就特么起了一个外设, 牛逼, java党表示不服...
BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service with a 128-bit UUID (32 characters exclusive of dashes).   生成一个128位的UUID, 目的是生成一个service. 具体的方法, 参考ble的协议要求文档,core什么的...
// Long UUID denote custom user created UUID

// create switch characteristic and allow remote device to read and write

//下面就是创建一个对象的方法类似, 创建一个led的特征字, 可读可写
BLECharCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);  
// create button characteristic and allow remote device to get notifications

//下面创建一个按钮用的特征字, 可读可通知.
BLECharCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // allows remote device to get notifications
// Note use of Typed Characteristics. These previous 2  characeristics are of the type char

//setup是特么阿追诺的特色(shai)
void setup() {

//设置串口9600
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output 设置对应的pin脚为输出
  pinMode(buttonPin, INPUT); // use button pin 4 as an input   button的pin脚是输入.

  // set the local name peripheral advertises   设置本地广播名, 问题是似乎设置了, 没用...
  blePeripheral.setLocalName("SmartJar");
  // set the UUID for the service this peripheral advertises:

//设置外设的广播用UUID
  blePeripheral.setAdvertisedServiceUuid(ledService.uuid());

  // add service and characteristics

//添加服务与特征字.
  blePeripheral.addAttribute(ledService);
  blePeripheral.addAttribute(ledCharacteristic);
  blePeripheral.addAttribute(buttonCharacteristic);

  // set initial values for led and button characteristic

//设置初始值
  ledCharacteristic.setValue(0);
  buttonCharacteristic.setValue(0);

  // advertise the service

//广播
  blePeripheral.begin();

//串口打印.
  Serial.println("Bluetooth device active, waiting for connections...");
}

//这里就是一个大while (1)
void loop() {
  // poll peripheral

//外设轮询
  blePeripheral.poll();

  // read the current button pin state

//读取目前的按键pin状态
  char buttonValue = digitalRead(buttonPin);

  // has the value changed since the last read

//看来要适应这种对象的写法. 判断button的值有没有改变.
  boolean buttonChanged = (buttonCharacteristic.value() != buttonValue);

  if (buttonChanged) {

//如果按键改变值, 就更新特征字, 两个特征字同时改.
    // button state changed, update characteristics
    ledCharacteristic.setValue(buttonValue);
    buttonCharacteristic.setValue(buttonValue);
  }

  if (ledCharacteristic.written() || buttonChanged) {

//写入任何, 或者按键改变, 都会在串口打印当前的LED灯的状态, 并实际性的改变LED的状态.
    // update LED, either central has written to characteristic or button state has changed
    // if you are using a phone or a BLE  central device that is aware of this characteristic, writing a value of 0x40 for example
    // Will be interpreted as written
    if (ledCharacteristic.value()) {
      Serial.println("LED on");
      digitalWrite(ledPin, HIGH);
    } else {
      // If central writes a 0 value then it is interpreted as no value and turns off the LED
      Serial.println("LED off");
      digitalWrite(ledPin, LOW);
    }
  }
}

Intel+Ardruino 101的更多相关文章

  1. Intel+Ardruino 101 翻转时点灯

    /*  ===============================================  Example sketch for CurieIMU library for Intel(R ...

  2. 了解 ARDUINO 101* 平台

    原文链接 简介 作为一名物联网 (IoT) 开发人员,您需要根据项目的不同需求,选择最适合的平台来构建应用. 了解不同平台的功能至关重要. 本文第一部分比较了 Arduino 101 平台和 Ardu ...

  3. 学习 Linux,101: Linux 命令行

    概述 本教程将简要介绍 bash shell 的一些主要特性,涵盖以下主题: 使用命令行与 shell 和命令交互 使用有效的命令和命令序列 定义.修改.引用和导出环境变量 访问命令历史和编辑工具 调 ...

  4. Arduino101学习笔记(三)—— 101简介

    一.板子图示--摘自中文社区 二.技术规格 主控器 Intel Curie 工作电压 3.3V (I/O兼容5V) 输入电压 (推荐) 7-12V 输入电压 (极限) 6-20V 数字 I/O 14 ...

  5. Intel X710网卡VxLAN offload 性能测试

    Intel X710网卡VxLAN offload性能测试 1.  测试环境参数: 交换机:盛科E580 服务器: Intel(R) Xeon(R) CPU E5-2650 v3 @ 2.30GHz ...

  6. Intel 移位指令的陷阱(转)

    今天发现了一个Intel逻辑左移指令shl的一个bug.   逻辑左移的概念是对给定的目的操作数左移COUNT次,每次移位时最高位移入标志位CF中,最低位补零. 其中OPRD1为目的操作数, 可以是通 ...

  7. Intel汇编指令格式解析

    环境: win7_x64旗舰版.VS2015企业版 一.Intel保护模式.实地址模式和虚拟8086模式指令格式(x86) 图在Intel手册2.1章节 1.1)Instruction Prefixe ...

  8. Intel daal数据预处理

    https://software.intel.com/en-us/daal-programming-guide-datasource-featureextraction-py # file: data ...

  9. intel:spectre&Meltdown侧信道攻击(四)—— cache mapping

    前面简单介绍了row hammer攻击的原理和方法,为了更好理解这种底层硬件类攻击,今天介绍一下cpu的cache mapping: 众所周知,cpu从内存读数据,最开始用的是虚拟地址,需要通过分页机 ...

随机推荐

  1. jQuery选择器总结(转)

    ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ...

  2. mysql开发中使用存储过程

    在mysql开发中使用存储过程的理由: 当希望在不同的应用程序或平台上执行相同的函数,或者封装特定功能时,存储过程是非常有用的 mysql 执行语句是要先编译,然后再执行的.这样如果查询并发大的时候. ...

  3. Power-BI这些饼图你用过吗

    Power-BI预设了多种饼图,除了常见的饼图.圆环图之外,还有嵌套饼图.并列饼图.百分比饼图.百分比弧形图.半径玫瑰图.面积玫瑰图等.不同的应用场景选择不同的饼图,让你的数据展现更丰富.更合理.更实 ...

  4. strtok&strsep

    strtok,strtok_r,strsep--extract tokens from strings Tje strsep() function was introduced as a replac ...

  5. CTE计算层级关系

    推广渠道表有ParentID字段,代表上下层级关系.现要统计每个推广员,推广了多少人? --创建表结构,插入测试数据 USE DBA_Monitor GO CREATE TABLE [dbo].[TG ...

  6. Swift游戏实战-跑酷熊猫 12 与平台的碰撞

    这节主要实现熊猫和平台的碰撞,实现熊猫在平台上奔跑 要点 对平台进行物理属性设置 //设置物理体以及中心点 self.physicsBody = SKPhysicsBody(rectangleOfSi ...

  7. Lintcode: Recover Rotated Sorted Array

    Given a rotated sorted array, recover it to sorted array in-place. Example [4, 5, 1, 2, 3] -> [1, ...

  8. JS练习题 显示登入者相关好友

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. navicat内的主键和外键

    数据库内的一个重点是主键另一个是外键 实体完整性{ 主键的全称:主关键字    它能够进行唯一标示某一列的 主键的三大特点是:唯一  非空  排序 一个没有主键的表不是一个完整的表,只要表设置了主键那 ...

  10. 最近兰州的js风格写个插件和一个template engine

    /* *@Product Name: Rational Framework Author: Calos Description: pager !important: pager */ (functio ...