亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Manufacturing Technology >> 制造工艺

Tech-TicTacToe

组件和用品

Arduino UNO
Arduino
× 1
MAX7219 LED 点阵
× 1
薄膜开关键盘
× 1

必要的工具和机器

热胶枪(通用)

应用和在线服务

Arduino IDE

关于这个项目

嗨黑客社区。

我是 Simone Adob​​s,这是我在 Hackster 上发布的第三个项目。这是我的第一个项目,我用纸板、纸和热胶枪创建了一个结构,其中包含 Arduino 和其他组件。

这是一个简短的视频,向您展示了 Tris 的工作原理:

在这里您可以从所有视图中看到该项目:

我希望你会喜欢它,因为我花了几个小时在它上面!现在让我们从项目开始。

Tris 是如何工作的?

答案很简单:当你在键盘上点击一个数字时,Arduino会打开相应的方块。

  • 我可以换球员吗?

当你打开一个方块时,Arduino会立即切换到下一个玩家的回合。

  • Arduino 会识别我何时获胜吗?

当玩家获胜时,Arduino 在 LED 点阵上写下:

  • 如果获胜者是玩家 1,则为“1”;
  • 如果获胜者是玩家 2,则为“2”。

游戏结束后,我可以通过按钮重新启动Arduino吗?

如果您单击键盘上的“0”按钮,您可以重新启动游戏 - Arduino 会自行重新启动。

如何识别玩家?

您可以轻松识别玩家,因为虽然 LED 点阵只有红色,但每个玩家都有由 2x2 LED 形成的特定图案:

  • 玩家 1 有这个模式:"\"
  • 玩家 2 有另一种模式:"/"

对于任何问题、建议、批评或代码解释,请随时在下面发表评论。如果你喜欢这个项目,请留下一个赞并看看我的其他项目!

尝试制作另一个结构或个性化我的结构并将其照片发送给我!

祝你有个美好的一天!

来自意大利的西蒙<3

代码

  • Tech-Tris
Tech-TrisC/C++
#include #include #include #include #define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {} LedControl lc=LedControl(12,10,11,1);bool player1=true,q1=false,q2=false,q3=false,q4=false,q5=false,q6=false,q7 =false,q8=false,q9=false;int row,col,rowPlays,colPlays,result,player,winner;char hexaKeys[4][3] ={ {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'}};int play[3][3 ] ={ {0,0,0}, {0,0,0}, {0,0,0}};byte rowPins[4] ={8, 7, 6, 5};byte colPins[3] ={4, 3, 2};Keypad customKeypad =Keypad(makeKeymap(hexaKeys), rowPins, colPins, 4, 3);无效设置(){ lc.shutdown(0,假); lc.setIntensity(0,0); lc.clearDisplay(0);}void loop() { int customKey =customKeypad.getKey();绘画(自定义键);获胜(结果); if (winner==1) { lc.clearDisplay(0); while (winner==1) { char customKey =customKeypad.getKey(); if (customKey=='0') { Reset_AVR(); lc.setLed(0,1,4,true); lc.setLed(0,2,5,true); lc.setLed(0,3,6,true); lc.setLed(0,4,7,true); lc.setLed(0,4,6,true); lc.setLed(0,4,5,true); lc.setLed(0,4,4,true); lc.setLed(0,4,3,true); lc.setLed(0,4,2,true); lc.setLed(0,4,1,true); lc.setLed(0,4,0,true); lc.setLed(0,5,0,true); lc.setLed(0,6,0,true); lc.setLed(0,3,0,true); lc.setLed(0,2,0,true); } } else if (winner==2) { lc.clearDisplay(0); while (winner==2) { char customKey =customKeypad.getKey(); if (customKey=='0') { Reset_AVR(); lc.setLed(0,2,0,true); lc.setLed(0,3,0,true); lc.setLed(0,4,0,true); lc.setLed(0,5,0,true); lc.setLed(0,2,1,true); lc.setLed(0,2,2,true); lc.setLed(0,2,3,true); lc.setLed(0,2,4,true); lc.setLed(0,3,4,true); lc.setLed(0,4,4,true); lc.setLed(0,5,4,true); lc.setLed(0,5,5,true); lc.setLed(0,5,6,true); lc.setLed(0,5,7,true); lc.setLed(0,4,7,true); lc.setLed(0,3,7,true); lc.setLed(0,2,7,true); } }}int round_player() { if (player1) { player1=false;结果=1; } else { player1=true;结果=2; } return result;}void win(int player) { if (plays[0][0]==player &&play[0][1]==player &&play[0][2]==player) { winner=播放器; } else if (plays[1][0]==player&&plays[1][1]==player&&plays[1][2]==player){winner=player; } else if (plays[2][0]==player&&plays[2][1]==player&&plays[2][2]==player){winner=player; } else if (plays[0][0]==player&&plays[1][0]==player&&plays[2][0]==player){winner=player; } else if (plays[0][1]==player&&plays[1][1]==player&&plays[2][1]==player){winner=player; } else if (plays[0][2]==player&&plays[1][2]==player&&plays[2][2]==player){winner=player; } else if (plays[0][0]==player&&plays[1][1]==player&&plays[2][2]==player){winner=player; } else if (plays[0][2]==player&&plays[1][1]==player&&plays[2][0]==player){winner=player; }}void switch_on_led(int col, int row, int colPlays, int rowPlays) { if (player1) { lc.setLed(0,col,row,true); lc.setLed(0,col+1,row-1,true); } else { lc.setLed(0,col,row-1,true); lc.setLed(0,col+1,row,true); } play[rowPlays][colPlays]=round_player();}void Painting(int bottone) { switch (bottone) { case 49:if (!q1){ switch_on_led(0,7,0,0); q1=真; } 休息;案例 50:if (!q2) { switch_on_led(3,7,0,1); q2=真; } 休息;案例 51:if (!q3) { switch_on_led(6,7,0,2); q3=真; } 休息;案例 52:if (!q4) { switch_on_led(0,4,1,0); q4=真; } 休息;案例 53:if (!q5) { switch_on_led(3,4,1,1); q5=真; } 休息;案例 54:if (!q6) { switch_on_led(6,4,1,2); q6=真; } 休息;案例 55:if (!q7) { switch_on_led(0,1,2,0); q7=真; } 休息;案例 56:if (!q8) { switch_on_led(3,1,2,1); q8=真; } 休息;案例 57:if (!q9) { switch_on_led(6,1,2,2); q9=真; } 休息;案例 48:Reset_AVR();休息; }}

示意图

tris_1Nd6QnEjNE.fzz

制造工艺

  1. 使用 Arduino 制作流光溢彩监视器
  2. Arduino Pong Game - OLED 显示器
  3. Giant Animatronics Lego Minfig 操作游戏
  4. 音频检测器
  5. Arduino Tamagotchi Clone - Digital Pet
  6. 无线灯开关操纵器
  7. 运动感应水枪
  8. Arduino 倒数计时器
  9. 带有 OK Google 的蓝牙语音控制设备
  10. Arduino 向日葵:电子太阳舞者
  11. 遥控保时捷汽车(Arduino 项目)
  12. 如何用 Arduino 制作音乐