×

IOTA动力婴儿摇椅

消耗积分:0 | 格式:zip | 大小:0.28 MB | 2022-12-20

张玉珍

分享资料个

描述

婴儿摇椅是适合婴儿坐下、摇晃和放松的好产品。但是,新生儿(0-3 米)不能自己摇晃,因此必须由成人帮助推动。

IOTA Powered Baby Rocker 通过为每个摇杆动作发送 IOTA 代币,为您提供额外的动力来帮助宝宝摇摆。

如何使用它

摇杆必须有一个帐户,其中包含一些可用的 IOTA 代币

1) 用户将他的接收 IOTA 地址连同一条消息发送到 Rocker 的打印地址

2)收到消息后,开始计数;OLED 显示屏显示动作,用户开始推动摇杆

3) 当用户停止推送时,摇杆将 IOTA 代币发送到用户的地址,具体取决于移动的次数。

4)终于,宝贝开心了,用户赚到了一些IOTA代币!双赢局面!:-)

 

准备好硬件

首先将 GPIO 排针焊接到 Pi Zero W,或者您可以使用已预焊接 GPIO 排针的 Pi Zero WH。

对于这个项目,我们需要 2 个模块,一个 MPU6050 加速度计+陀螺仪,用于计算摇杆的移动,一个 OLED 屏幕,用于向用户显示消息。两个模块都连接到 Pi Zero 的 I2C 总线。

对于 Raspberry Pi Zero W,引出线是:

PIN1 -> VCC

PIN3-> SDA

PIN5 -> SCL

PIN9 -> 接地

可以根据下图连接组件。

 
pYYBAGOhEsCAVtY-AAGCsfUpTJI351.png
 
 
poYBAGOhEsiAXNTJAAMrPPlMpms998.jpg
 

最后,将组件连接到摇杆上。我用双面胶带将它们固定到位。

 
poYBAGOhEtWAJVOWAAKd6keNRYc656.jpg
 

准备好软件

必须安装 Raspbian 和 Node.js。如果您还没有安装它们,请按照以下教程进行操作:

安装 Raspbian 教程

安装 Node.js 教程

您还必须按照以下说明启用 I2C 总线以与 OLED 显示器和 MPU6050 陀螺仪进行通信。

sudo raspi-config


 
pYYBAGOhEtqAKkQ8AACFclVEQxc219.png
 
 
pYYBAGOhEt2AAur_AABdTLp-fNA611.png
 

获取项目存储库

项目文件在 github 上公开可用。您可以通过以下方式克隆存储库

git clone https://github.com/simvoulos/IOTArocker.git

安装所需的库

npm install @iota/core
npm install i2c-bus
npm install oled-ssd1306-i2c
npm install oled-font-5x7
npm install i2c-mpu6050

为摇杆创建 IOTA 地址

Raspberry Pi Zero 的处理能力有限,从标准地址(安全级别 2)发送 IOTA 代币需要花费大量时间来签署传输。因此,为了让我们的 Pi Zero 更容易,我们必须使用安全级别 1 地址。要创建这些地址,我们可以使用我们项目的 CreateRockerAddress.js(不要忘记设置摇杆的种子)。CreateRockerAddress.js 将创建 2 个地址,一个用于接收用户消息的地址,一个用于为摇杆帐户提供资金的地址。

设定参数

在我们的主项目文件 IOTARocker.js 中,我们必须设置以下变量

  • seed :摇杆的 IOTA 帐户的种子。请记住,该帐户必须有一些 IOTA 代币。
  • msgAddress :摇杆将监听传入消息的地址
  • IOTAperMove :摇杆的每次移动将向用户发送多少 IOTA 代币

代码(IOTARocker.js)

代码分为 3 个部分。第一部分是摇杆侦听传入消息事务的地方。该消息必须包含用户的 IOTA 地址,付款将发送到该地址。当一条消息到达时,代码移动到第二部分,它开始通过使用 MPU6050 模块检查摇杆的旋转来计算移动次数。当一段时间没有检测到移动时,代码的第三部分开始。在第三部分中,Pi Zero 将 IOTA 代币发送给用户。代币数量通过公式TokensToSend = moves * IOTAperMove 计算。

 
poYBAGOhEuGAWwHUAAA0eTtrqio037.png
 

 


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.lene-v.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'IOTA动力婴儿摇椅',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.lene-v.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);