俗话说“小赌怡情,大赌兴业”,经过考证我们能够确信这个叫做”俗话“的名人是赌场老板—-看过余华先生的《活着》对此肯定深有体会,再多说一句,我个人不觉得这部小说讲述的是一个悲剧故事,生活就是这样而已,过去是这样现在依然是这样。小说没有被禁,但是对应的电影在国内是禁片。有这样一种说法”昨晚在暨大演讲,有同学问我《活着》改编电影时什么事情印象深刻?我说这是18年前的事了,还记得当时张艺谋时常说原作里的什么细节要改动,审查才能通过。看他胸有成竹的模样,心想他如此了解xxx,对他十分钦佩。可是张艺谋拍摄完成电影后,审查还是没有通过。我不再钦佩张艺谋,我钦佩xxx了“【参考1】。
从概率的角度来说,哪怕对方比你获胜的概率只高了2%,在你”根本停不下“的情况下,蚀本只是时间问题…….
前面介绍了一个 Arduino 打造的”电子骰子“,我们下面要对它进行改装,让你”稳赢不输“。
我们再添加一个遥控设备,它在我们之前的《用 Arduino 打造PPT遥控器》中出场过,是目很容易买到价格低廉的遥控设备。
和之前的相比,只是多了一个接收器。接收器上有5个Pin,这个接收器和 Arduino 的连接如下:
5V <——> 5v (我试过如果用 3.3v的话不工作)
GND<——> GND
D0 <——> D4
D1 <——> D5
D2 <——> D6
D3 <——> D7
按键比较少,所以只支持对应了从3到6个点数。改造之前的程序,加入检查遥控按键是否被按下的代码。
/* 日期:2014-7-2 功能:MAX7219驱动8*8点阵 作者:Z.t IDE:1.0.5 硬件:最小系统UNO 说明:本代码主要参考了官方的示例程序 */ //官方的库 #include "LedControl.h" /* Now we need a LedControl to work with. ***** These pin numbers will probably not work with your hardware ***** 第一个参数:pin 12 is connected to the DataIn 第二个参数:pin 11 is connected to the CLK 第三个参数:pin 10 is connected to LOAD 第四个参数:We have only a single MAX72XX. */ LedControl lc=LedControl(12,11,10,1); /* we always wait a bit between updates of the display */ unsigned long delaytime=50; int ButtonPin=3; int PinA=4; int PinB=5; int PinC=6; int PinD=7; int Current=1; int Actual=0xFF; boolean MarkStart=false; //标记是否按键抬起 void setup() { /* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */ lc.shutdown(0,false); /* Set the brightness to a medium values */ lc.setIntensity(0,8); /* and clear the display */ lc.clearDisplay(0); randomSeed(analogRead(0)); pinMode(ButtonPin, INPUT); pinMode(PinA, INPUT); pinMode(PinB, INPUT); pinMode(PinC, INPUT); pinMode(PinD, INPUT); } void showNum(int x) { /* here is the data for the characters */ byte one[8]={ B00000000, B00000000, B00000000, B00111000, B00111000, B00000000, B00000000, B00000000}; byte two[8]={ B00000000, B00000110, B00000110, B00000000, B00000000, B01100000, B01100000, B00000000}; byte three[8]={ B00000000, B00111000, B00111000, B00000000, B01100110, B01100110, B01100110, B00000000}; byte four[8]={ B00000000, B01100110, B01100110, B00000000, B00000000, B01100110, B01100110, B00000000}; byte five[8]={ B00000000, B01100110, B01100110, B00011000, B00011000, B01100110, B01100110, B00000000}; byte six[8]={ B01100110, B01100110, B00000000, B01100110, B01100110, B00000000, B01100110, B01100110}; switch (x) { case 1: lc.setRow(0,0,one[0]); lc.setRow(0,1,one[1]); lc.setRow(0,2,one[2]); lc.setRow(0,3,one[3]); lc.setRow(0,4,one[4]); lc.setRow(0,5,one[5]); lc.setRow(0,6,one[6]); lc.setRow(0,7,one[7]); break; case 2: lc.setRow(0,0,two[0]); lc.setRow(0,1,two[1]); lc.setRow(0,2,two[2]); lc.setRow(0,3,two[3]); lc.setRow(0,4,two[4]); lc.setRow(0,5,two[5]); lc.setRow(0,6,two[6]); lc.setRow(0,7,two[7]); break; case 3: lc.setRow(0,0,three[0]); lc.setRow(0,1,three[1]); lc.setRow(0,2,three[2]); lc.setRow(0,3,three[3]); lc.setRow(0,4,three[4]); lc.setRow(0,5,three[5]); lc.setRow(0,6,three[6]); lc.setRow(0,7,three[7]); break; case 4: lc.setRow(0,0,four[0]); lc.setRow(0,1,four[1]); lc.setRow(0,2,four[2]); lc.setRow(0,3,four[3]); lc.setRow(0,4,four[4]); lc.setRow(0,5,four[5]); lc.setRow(0,6,four[6]); lc.setRow(0,7,four[7]); break; case 5: lc.setRow(0,0,five[0]); lc.setRow(0,1,five[1]); lc.setRow(0,2,five[2]); lc.setRow(0,3,five[3]); lc.setRow(0,4,five[4]); lc.setRow(0,5,five[5]); lc.setRow(0,6,five[6]); lc.setRow(0,7,five[7]); break; case 6: lc.setRow(0,0,six[0]); lc.setRow(0,1,six[1]); lc.setRow(0,2,six[2]); lc.setRow(0,3,six[3]); lc.setRow(0,4,six[4]); lc.setRow(0,5,six[5]); lc.setRow(0,6,six[6]); lc.setRow(0,7,six[7]); break; } } void loop() { int Next; if (digitalRead(PinA)==HIGH) {Actual=3;} if (digitalRead(PinB)==HIGH) {Actual=4;} if (digitalRead(PinC)==HIGH) {Actual=5;} if (digitalRead(PinD)==HIGH) {Actual=6;} if (digitalRead(ButtonPin)==LOW) { showNum(Current); do { Next=random(1,7); } while (Current==Next); //因为如果两次出现相同的数字,看起来 //会觉得没有变,所以这里要保证生成不同 Current=Next; delay(delaytime); MarkStart=true; } if ((MarkStart==true) && (digitalRead(ButtonPin)==HIGH)){ //按键抬起,生成实际显示的结果 MarkStart=false; if (Actual==0xFF) {showNum(random(1,7));} //如果当前未收到选择,随机生成一个 else {showNum(Actual);} //收到过选择,那么就显示 Actual=0xFF; } }
和上一个电子骰子相比,这个接线看起来复杂多了,这是视觉差异而已,看起来多了很多线因为5V和GND用的比较多而已,所以导入面包板,都从上面取电而已。
程序下载 dice2
最后这篇文章告诉大家了一个非常重要的事实就是:不要和电子的赌博机游戏,因为你根本不可能赢。如果真的有人对你这样炫耀,存在的三种可能性是:
1.他在作弊
2.机器坏了
3.他想拉你一起入伙(这个可能性最大)
参考:
1:很早之前听说过这个事情,但是一直没有找到出处。从目前能够搜索到的资料看,来源应该是余华的微博
http://tieba.baidu.com/p/1621656047
2.http://www.lab-z.com/arduinodice1/ 本系列的第一篇文章
3.http://www.lab-z.com/%E7%94%A8-arduino-%E6%89%93%E9%80%A0ppt%E9%81%A5%E6%8E%A7%E5%99%A8/ 用-arduino-打造ppt遥控器