热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Intel+Ardruino101

为了传说中的那啥,啊,嗯..#includeconstintledPin13;setledPintoon-boardLEDLED的pin脚就是14const

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

#include

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


推荐阅读
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • 在project.properties添加#Projecttarget.targetandroid-19android.library.reference.1..Sliding ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • 本文介绍了一种解析GRE报文长度的方法,通过分析GRE报文头中的标志位来计算报文长度。具体实现步骤包括获取GRE报文头指针、提取标志位、计算报文长度等。该方法可以帮助用户准确地获取GRE报文的长度信息。 ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • FineReport平台数据分析图表显示部分系列接口的应用场景和实现思路
    本文介绍了FineReport平台数据分析图表显示部分系列接口的应用场景和实现思路。当图表系列较多时,用户希望可以自己设置哪些系列显示,哪些系列不显示。通过调用FR.Chart.WebUtils.getChart("chartID").getChartWithIndex(chartIndex).setSeriesVisible()接口,可以获取需要显示的系列图表对象,并在表单中显示这些系列。本文以决策报表为例,详细介绍了实现方法,并给出了示例。 ... [详细]
author-avatar
专业破解王_920
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有