Sorter monet - Prototyp cz.1

Z potrzeby chwili postanowilem zbudować sorter monet polskich. Wybór padł na Arduino jako że jest tanie i w miarę proste w nauce. Nie przeciągając zbytnio przejdźmy do zadania głównego.

CEL:

  • Sumować wartość monet: 10gr, 20gr, 50gr, 1zł, 2zł, 5zł
  • Zliczać ilość wszystkich wrzuconych monet
  • zajmować możliwie jak najmniej miejsca

Wykorzystane elementy w projekcie:

  • Arduino nano
  • rezystor 220 Ohm - 5szt.
  • dioda led niebieska - 5szt.
  • przycisk mikroswitch - 5szt.
  • Płytka prototypowa
  • przewody połączeniowe

Łączymy elementy tak jak na przedstawionym schemacie poniżej

Teraz czas na napisanie programu.

 


/*
SORTER MONET GarazPomyslow.pl 10-03-2018
kontakt@garazpomyslow.pl
*/

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); 

const int  coin1Pin = 3;   
const int  coin5Pin = 4; 
const int  coin10Pin = 5;   
const int  coin25Pin = 6;   
const int  coin100Pin = 7;    
const int  coin200Pin = 8;    
const int  led1 = 9;    
const int  led5 = 10;   
const int  led10 = 11;   
const int  led25 = 12;  
const int  led100 = 13;  
const int  led200 = 14;  


unsigned long  coin1counter = 0;  
unsigned long  coin5counter = 0;  
unsigned long  coin10counter = 0;  
unsigned long  coin25counter = 0;  
unsigned long  coin100counter = 0; 
unsigned long  coin200counter = 0;   



float coin1total = coin1counter*0.10;  
float coin5total = coin5counter*0.20;  
float coin10total = coin10counter*0.50;  
float coin25total = coin25counter*1.00;   
float coin100total = coin100counter*2.00;  
float coin200total = coin200counter*5.00;   
int totalcoins = coin1counter+coin5counter+coin10counter+coin25counter+coin100counter+coin200counter;
float totalcash = coin1total+coin5total+coin10total+coin25total+coin100total+coin200total;

void setup() {

 pinMode(coin1Pin, INPUT_PULLUP);
 pinMode(coin5Pin, INPUT_PULLUP);
 pinMode(coin10Pin, INPUT_PULLUP);
 pinMode(coin25Pin, INPUT_PULLUP);
 pinMode(coin100Pin, INPUT_PULLUP);
 pinMode(coin200Pin, INPUT_PULLUP);
 pinMode(led1, OUTPUT);
 pinMode(led5, OUTPUT); 
 pinMode(led10, OUTPUT); 
 pinMode(led25, OUTPUT);  
 pinMode(led100, OUTPUT);
 pinMode(led200, OUTPUT); 
 
 lcd.begin();
 lcd.setCursor(0,0);
 lcd.print("Sorter monet");
 lcd.setCursor(0,1);
 lcd.print("Starting.");
 delay(100);
 lcd.setCursor(0,1);
 lcd.print("Starting..");
 delay(100);
 lcd.setCursor(0,1);
 lcd.print("Starting...");
 delay(100);
 lcd.setCursor(0,1);
 lcd.print("Starting....");
 delay(100);
 lcd.setCursor(0,1);
 lcd.print("Starting.....");
 delay(100);
 lcd.setCursor(0,1);
 lcd.print("Starting......");
 delay(100);
 lcd.setCursor(0,1);
 lcd.print("Starting.......");
 delay(100);
 lcd.setCursor(0,1);
 lcd.print("Starting........");
 delay(100);
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("www.garazpoomyslow.pl");
 delay(1000);
 lcd.clear();
}


void loop() {

     int coin1_state = digitalRead(coin1Pin);
     int coin5_state = digitalRead(coin5Pin);
     int coin10_state = digitalRead(coin10Pin);
     int coin25_state = digitalRead(coin25Pin);
     int coin100_state = digitalRead(coin100Pin);
     int coin200_state = digitalRead(coin200Pin);



delay (100);

 if (coin1_state == LOW && digitalRead(coin1Pin == LOW)) {  
     coin1counter ++;
     digitalWrite(led1, HIGH);
}
 if (coin5_state == LOW && digitalRead(coin5Pin == LOW)) {  
     coin5counter++; 
     digitalWrite(led5, HIGH);
}
 if (coin10_state == LOW && digitalRead(coin10Pin == LOW)) {  
     coin10counter++; 
     digitalWrite(led10, HIGH);
}
 if (coin25_state == LOW && digitalRead(coin25Pin == LOW)) {  
     coin25counter++; 
     digitalWrite(led25, HIGH);
}
 if (coin100_state == LOW && digitalRead(coin100Pin == LOW)) {  
     coin100counter++; 
     digitalWrite(led100, HIGH);
}
 if (coin200_state == LOW && digitalRead(coin200Pin == LOW)) {  
     coin200counter++;
     digitalWrite(led200, HIGH);
}

     UpdateTotals();
     lcd.print("                ");
     lcd.setCursor(0,0);
     lcd.print("SUMA:");
     lcd.print(totalcash);
     lcd.print(" PLN");
        lcd.setCursor(0,1);
        lcd.print("# Monet:");
        lcd.print(totalcoins);
        
     
     digitalWrite(led1, LOW);
     digitalWrite(led5, LOW);
     digitalWrite(led10, LOW);
     digitalWrite(led25, LOW);
     digitalWrite(led100, LOW);
     digitalWrite(led200, LOW);

 //delay(200);
}
void UpdateTotals(){

coin1total = coin1counter*0.10;
coin5total = coin5counter*0.20;
coin10total = coin10counter*0.50;
coin25total = coin25counter*1.00;
coin100total = coin100counter*2.00;
coin200total = coin200counter*5.00;
totalcoins = coin1counter+coin5counter+coin10counter+coin25counter+coin100counter+coin200counter;
totalcash = coin1total+coin5total+coin10total+coin25total+coin100total+coin200total;
}

 

 

Dodaj komentarz