得益于“Charlieplexing技术”,构造大大简化。
轮盘是一种游戏,其名称源于法语单词“小轮子”,很可能源自意大利游戏“Biribi”。在游戏中,玩家可以选择投注单个数字、不同组合的数字、红色或黑色、奇数或偶数,以及数字大小(19-36)或小数(1-18)。为了确定获胜数字,荷官会朝一个方向旋转轮盘,然后朝相反方向旋转滚珠,使其沿着轮盘外缘倾斜的圆形轨道旋转。
轮盘有两种流行类型:美式轮盘和欧式轮盘。欧式轮盘只有一个零,而美式轮盘有两个零。两者的数字顺序也不同。
这次我将向您介绍如何制作电子版欧洲轮盘,其中球的运动通过 LED 的连续点亮来模拟。
请注意,您可以在“www.theohupkens.nl/English/RouletteWheel.html”上查看原始项目,我只对代码进行了轻微修改,增加了一个旋转持续时间级别。在我之前的一个视频(https://www.youtube.com/watch?v=H_85lFRJ9T8&t=7s)中,我也演示了 Arduino 轮盘赌,但它的制作过程要复杂得多,难度也更大。
这次采用了 Charlieplexing 技术,也称为三态复用、减少引脚数的 LED 复用、互补 LED 驱动和交叉复用。这是一种用于驱动多路复用显示器的技术,利用微控制器上相对较少的 I/O 引脚来驱动大型 LED 阵列。

由于采用了这种技术,这次省去了 74HC595 移位寄存器,并且该设备的构建非常简单。它仅包含几个组件:
Arduino Nano微控制器
37个LED
五个电阻器
按钮,
和议长
关于二极管的连接方式,简单介绍一下。第一个二极管直接连接到 D11 引脚,并通过合适的电阻接地。其余 36 个二极管分为 4 组,每组 9 个。每组的阴极通过电阻连接到 A1 至 A4 模拟引脚。每组的阳极按顺序连接(例如:Led2、Led11、Led20、Led29 连接在一起并连接到 Arduino 的 D2 引脚),这 9 个端子连接到 Arduino 的 D2 至 D10 引脚。

现在让我们看看该设备在实际中是如何工作的:
启动后,四个 LED 会短时间旋转。启动后,四个 LED 会短时间旋转,之后一个 LED 会保持亮起状态。要转动球(LED),我们必须按下按钮,松开按钮后游戏就开始了。球的旋转时长有三个级别。如果按下按钮少于 0.5 秒,旋转速度最低;0.5 到 5 秒为正常旋转速度;最后,如果按下按钮超过 5 秒,则需要一分钟或更长时间才能停止球。
在球移动的整个过程中,扬声器都会发出特征声音。
下面你可以看到该设备的制作方式
最后,将整个装置安装在合适的盒子中,该盒子由厚度为3毫米的PVC板制成,并用自粘彩色壁纸覆盖。




项目代码
// Roulette, European Wheel
// c(2017) Th.M. Hupkens. Tested with an Arduino nano
#define PushButton 12
#define Click A5
#define ZeroLed 11
int quarter = A1; // Keeps track of in which quarter the current led is
int led; // Keeps track of which led is ON
bool CCW = true; // Counter clockwise
void setup() {
for (int i = 2; i <= 11; i++) pinMode(i, OUTPUT);
pinMode(PushButton, INPUT_PULLUP);
for (int a = A1; a <= A5; a++) pinMode(a, OUTPUT); // LOW = ON
for (int nowmber = 1; nowmber < 4; nowmber++)
for (int i = 2; i <= 10; i++) { // Animation when wheel starts up
digitalWrite(i, HIGH);
delay(200 - nowmber * 40 - (i - 2) * 5);
digitalWrite(i, LOW);
}
randomSeed(analogRead(A0)); // Initialise the random nowmber generator
led = random(2, 11); quarter = random(A1, A5); // choose led from 1 to 10; choose quarter from A1 to A4
for (int a = A1; a <= A4; a++) digitalWrite(a, a != quarter); digitalWrite(led, HIGH);
}
void loop() {
while (digitalRead(PushButton));
unsigned long now = millis();
while (!digitalRead(PushButton));
unsigned long tijd = millis() - now;
int Steps = 37 + random(18); // For the time being
if (tijd > 500) Steps *= 2; // Pressing the push button more than half a second gives a longer roll
if (tijd > 5000) Steps *= 2.01;
int Stap = 1;
while (Stap < Steps) {
Stap++;
digitalWrite(led, LOW);
if (CCW) {
led++;
if (led > 10) {
if (quarter == A4) {
if (led > 11) {
quarter = A1;
led = 2;
}
}
else {
led = 2;
quarter++;
}
}
}
else { // if NOT counter clockwise
led--;
if (led < 2) {
if (quarter == A1) {
led = ZeroLed;
quarter = A4;
}
else {
led = 10;
quarter--;
}
}
}
for (int a = A1; a <= A4; a++) digitalWrite(a, a != quarter); // if a is not the current quarter then a -> HIGH else a -> LOW
digitalWrite(led, HIGH);
digitalWrite(Click, HIGH); delayMicroseconds(40); digitalWrite(Click, LOW);
unsigned int delaytijd = 40 + Stap * 5;
if (tijd > 500) delaytijd /= 2;
delay(delaytijd);
}
CCW = !CCW;
}
附录
【Arduino 动手做】如何制作最简单的Arduino欧洲轮盘游戏
项目链接:https://www.hackster.io/mircemk/how-to-make-simplest-arduino-european-roulette-game-64960b
项目作者:北马其顿 米尔塞姆克(Mirko Pavleski)
项目视频 :https://www.youtube.com/watch?v=oU-7Vgl9Ins
项目代码:https://www.hackster.io/code_files/640589/download
油炸图:https://hacksterio.s3.amazonaws.com/uploads/attachments/1571043/untitled_sketch_2_y0ThMbZFpU.fzz

评论