Week18:Project development

Previous weekAssignment list| No more next week

idea and functions


the shooting target pcb board

input

input

input


laser cutter the outter box.

input
input

input
input


Dart with magnet

input


Fabduino testing

input

input


programming the sketch

input



display the lcd message on the computer

live play demo!


#include <Wire.h>  // Arduino IDE 內建
// LCD I2C Library,從這裡可以下載:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
#include <LiquidCrystal_I2C.h>

// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // 設定 LCD I2C 位址

const int Led = 13 ;// define LED Interface
const int btn10 = 10;
const int btn11 = 11;
const int btn12 = 12;
const int debounceDelay = 20;

int enter; // green
int change; // orange
int reset; //red
int temp;
int player1_score = 20;
int player2_score = 0;
int score;
int score_old;
int btn2_score = 2;
int btn3_score = 3;
int btn4_score = 4;
int btn5_score = 5;
int btn6_score = 6;
int btn7_score = 7;
const int btn2 = 2;
const int btn3 = 3;
const int btn4 = 4;
const int btn5 = 5;
const int btn6 = 6;
const int btn7 = 7;
char line1;
char line2;
int a[5] = {10, 20, 30, 40, 50};

/////////////////////////////////init, run once///////////////////
void setup() {
  Serial.begin(9600);  // 用於手動輸入文字
  //   pinMode (Led, OUTPUT) ; // define LED as output interface
  pinMode (btn12, INPUT);
  digitalWrite(btn12, HIGH);
  pinMode (btn11, INPUT);
  digitalWrite(btn11, HIGH);
  pinMode (btn10, INPUT);
  digitalWrite(btn10, HIGH);
  pinMode (btn2, INPUT);
  digitalWrite(btn2, HIGH);
  pinMode (btn3, INPUT);
  digitalWrite(btn3, HIGH);
  pinMode (btn4, INPUT);
  digitalWrite(btn4, HIGH);
  pinMode (btn5, INPUT);
  digitalWrite(btn5, HIGH);
  pinMode (btn6, INPUT);
  digitalWrite(btn6, HIGH);
  pinMode (btn7, INPUT);
  digitalWrite(btn7, HIGH);
  lcd.begin(16, 2);      // 初始化 LCD,一行 16 的字元,共 2 行,預設開啟背光

  // 閃爍三次
  for (int i = 0; i < 3; i++) {
    lcd.backlight(); // 開啟背光
    delay(250);
    lcd.noBacklight(); // 關閉背光
    delay(250);
  }
  lcd.backlight();
  // 輸出初始化文字
  lcdoutput("Hello World", "Have a nice day!");
  delay(1000);
  lcd.clear();
  lcdoutput("Push Green btn", "to start!");
  player1_score = a[0];
}
/////////////////////////////init end///////////////////

void loop() {
  temp = 0;
  int k = 0;
  if (digitalRead(btn10) == LOW) {
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 2; j++) {
        playgame();
        if (score > player1_score) {
          score = score_old;
          scoreoutput(1, score);
          delay(1000);
        }
        if (player1_score == score) {
          break;
        }
      }
      if (player1_score == score) {
        break;
      }
    }
    do {
      lcdoutput("Game Over! Push", "Green to restart");
      score = 0;
    } while (digitalRead(btn11) == LOW);
  }
  else if (digitalRead(btn11) == LOW) {
    lcdoutput("Set the score", "");
    while (digitalRead(btn11) == HIGH) {
      if (digitalRead(btn10) == LOW) {
        delay(300);
        k++;
        if (k > 4) {
          k = 0;
        }
        player1_score = a[k];
        scoreoutput(0, player1_score);
      }
      else if (digitalRead(btn12) == LOW) {
        delay(300);
        k--;
        if (k < 0) {
          k = 4;
        }
        player1_score = a[k];
        scoreoutput(0, player1_score);
      }
    }
    lcdoutput("OK! Push Green ", "to start");
  }
  else if (digitalRead(btn12) == LOW) {
    //play mode change
    lcdoutput("Hi There, PUSH", "GREEN BUTTON!");
  }
}

/////////////////////////////////////////////////single shooting process
void playgame() {
  lcdoutput("Please shoot!", "");
  delay(500);
  score_old = score;
  while (shooting_score() == 0);
  scoreoutput(1, score);
  delay(500);
  lcdoutput("Remove the dart, then", "click orange ");
  delay(500);
  lcdoutput("button.", "");
  while (removedetect() == 0);
}
/////////////////////////////////////single shooting process end


//////////////////////////remove detect
int removedetect() {
  //set lcd to wait remove
  int x = 0;

  if (digitalRead(btn11) == LOW && digitalRead(btn2) == HIGH && digitalRead(btn3) == HIGH && digitalRead(btn4) == HIGH && digitalRead(btn5) == HIGH && digitalRead(btn6) == HIGH && digitalRead(btn7) == HIGH) {
    x = 1;
  }
  return x;
}
///////////////////////////////////////////remove detect end


//////////////////////////////////////////////lcd display function
void lcdoutput(char* line1, char* line2) {
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 0); // 設定游標位置在第一行行首
  lcd.print(line1);
  delay(100);
  lcd.setCursor(0, 1); // 設定游標位置在第二行行首
  lcd.print(line2);
  delay(100);
  Serial.println(line1);
  Serial.println(line2);
}
/////////////////////////lcd display funcition end

////////////////////////shooting detect and return score

int shooting_score() {
  int y = 0;
  if (digitalRead(btn2) == LOW) {
    score = score + 2;
    delay(500);
    y = 1;
  }
  else if (digitalRead(btn3) == LOW) {
    score = score + 3;
    delay(500);
    y = 1;
  }
  else if (digitalRead(btn4) == LOW) {
    score = score + 4;
    delay(500);
    y = 1;
  }
  else if (digitalRead(btn5) == LOW) {
    score = score + 5;
    delay(500);
    y = 1;
  }
  else if (digitalRead(btn6) == LOW) {
    score = score + 6;
    delay(500);
    y = 1;
  }
  else if (digitalRead(btn7) == LOW) {
    score = score + 7;
    y = 1;
    delay(500);
  }
  return y;
}

///////////////////////////shooting detect and return score end

/////////////////////////////lcd score display function
void scoreoutput(int line1, int line2) {
  lcd.clear();
  lcd.setCursor(0, 0); // 設定游標位置在第一行行首
  lcd.print("Player   score");
  lcd.setCursor(0, 1); // 設定游標位置在第二行行首
  lcd.print(line1);
  lcd.print("       ");
  lcd.print(line2);
  Serial.println(line2);
}
////////////////////////////lcd score display funcition end

Use vinyl cutter to cut the point number.

input
input
input
input
input
input
input


force error: the dart contact two target pcb board

please refer to other assignment documentation to check the design step

input

About meassignmentAbout Final Project

Creative Commons License
Che-Yun Chuang 2015 fabacademy assignment is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.