基于Arduino制作的简易投币机(未完善)

标签:arduino

策策Phantom 发布于 2017-05-07 23:04

Step 1: 目前材料

格式工厂IMG_8043.jpg 格式工厂IMG_8038.jpg
1个Arduino板
1个LED灯
1个数码管
1个光敏传感器
一个盒子。。。
电源。。。
一些线。。。。。。。

Step 2: 原理

利用LED做光源,通过用硬币遮挡光源,引起光传感器数值变化,来改变数码管中数字显示。
 还无法判断硬币真假。。。

Step 3: 代码 (只写了数字0-4)

微信图片_20170507230202.png

int _ABVAR_1_x = 0 ;
int _ABVAR_2_k = 0 ;
void __ardublockDigitalWrite(int pinNumber, boolean status)
{
  pinMode(pinNumber, OUTPUT);
  digitalWrite(pinNumber, status);
}

void m1();
void m2();
void m3();
void m4();
void m0();

void setup()
{
  pinMode( 3 , OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  if (( ( _ABVAR_1_x ) == ( 0 ) ))
  {
    delay( 1000 );
    _ABVAR_1_x = 1 ;
  }
  analogWrite(3 , 255);
  Serial.print("message");
  Serial.print(analogRead(0));
  Serial.println();
  if (( ( analogRead(0) ) < ( 10 ) ))
  {
    delay( 1000 );
    _ABVAR_2_k = ( _ABVAR_2_k + 1 ) ;
    Serial.print("k");
    Serial.print(_ABVAR_2_k);
    Serial.println();
  }
  if (( ( _ABVAR_2_k ) == ( 0 ) ))
  {
    m0();
  }
  if (( ( _ABVAR_2_k ) == ( 1 ) ))
  {
    m1();
  }
  if (( ( _ABVAR_2_k ) == ( 2 ) ))
  {
    m2();
  }
  if (( ( _ABVAR_2_k ) == ( 3 ) ))
  {
    m3();
  }
  if (( ( _ABVAR_2_k ) == ( 4 ) ))
  {
    m4();
  }
}

void m4()
{
  __ardublockDigitalWrite(13, LOW);
  __ardublockDigitalWrite(12, HIGH);
  __ardublockDigitalWrite(11, HIGH);
  __ardublockDigitalWrite(10, LOW);
  __ardublockDigitalWrite(9, LOW);
  __ardublockDigitalWrite(8, HIGH);
  __ardublockDigitalWrite(7, HIGH);
  __ardublockDigitalWrite(6, LOW);
}

void m1()
{
  __ardublockDigitalWrite(13, LOW);
  __ardublockDigitalWrite(12, HIGH);
  __ardublockDigitalWrite(11, HIGH);
  __ardublockDigitalWrite(10, LOW);
  __ardublockDigitalWrite(9, LOW);
  __ardublockDigitalWrite(8, LOW);
  __ardublockDigitalWrite(7, LOW);
  __ardublockDigitalWrite(6, LOW);
}

void m0()
{
  __ardublockDigitalWrite(13, HIGH);
  __ardublockDigitalWrite(12, HIGH);
  __ardublockDigitalWrite(11, HIGH);
  __ardublockDigitalWrite(10, HIGH);
  __ardublockDigitalWrite(9, HIGH);
  __ardublockDigitalWrite(8, HIGH);
  __ardublockDigitalWrite(7, LOW);
  __ardublockDigitalWrite(6, LOW);
}

void m3()
{
  __ardublockDigitalWrite(13, HIGH);
  __ardublockDigitalWrite(12, HIGH);
  __ardublockDigitalWrite(11, HIGH);
  __ardublockDigitalWrite(10, HIGH);
  __ardublockDigitalWrite(9, LOW);
  __ardublockDigitalWrite(8, LOW);
  __ardublockDigitalWrite(7, HIGH);
  __ardublockDigitalWrite(6, LOW);
}

void m2()
{
  __ardublockDigitalWrite(13, HIGH);
  __ardublockDigitalWrite(12, HIGH);
  __ardublockDigitalWrite(11, LOW);
  __ardublockDigitalWrite(10, HIGH);
  __ardublockDigitalWrite(9, HIGH);
  __ardublockDigitalWrite(8, LOW);
  __ardublockDigitalWrite(7, HIGH);
  __ardublockDigitalWrite(6, LOW);
}

Step 4: 展示。

格式工厂格式工厂IMG_8039.jpg 格式工厂格式工厂IMG_8044.jpg 格式工厂格式工厂IMG_8045.jpg
 
云泥坊2017-05-12 10:51:24
好赞啊,这次的全国比赛当中看到了好几个类似的作品
策策Phantom2017-05-08 08:10:31
http://m.youku.com/video/id_XMjc1MDcyOTQ2NA==.html?spm=a2h2a.8293802.0.0

作者

策策Phantom

浙江,温州

1粉丝 2作品 0随笔
  关注 私信


阅读数: 2465