Airsoft Krispies

Bonjour à tous et bienvenue


    Projet Valise multi mode

    Partagez

    astur

    Messages : 14
    Date d'inscription : 10/11/2017

    Projet Valise multi mode

    Message par astur le Ven 10 Nov - 10:56

    Salut à tous !

    Je me remet dans mes projets gentillement en essayant de recabler un multi mode que j'ai trouver ici : http://www.instructables.com/id/ARDUINO-AIRSOFT-TIME-BOMB-GAME/

    alors déjà je n'arrive pas a le modifier pour un lcd I2C une vrai galère.

    mais surtout lorsque je passe sur un écran classique et que je le cable, j'ai à l'affichage une série de caractère aléatoire qui se décale lorsque je clic sur reset.

    je n'ai pour le moment connecté que le lcd et le clavier pour tester.

    Voici le code du début :

    #include
    #include
    //#include
    #include
    /*
    Arduino Bomb Pro

    The circuit:
    * More info at : http://yin.mainstreamds.com/
    If you need some help mail me to yinbot@gmail.com

    created 4,Sep, 2010
    Modified 24 May 2014
    by Ignacio Lillo

    */

    const char* menu1[]={"Search&Destroy","Sabotage","Domination", "Configuration" };
    const char* menu2[]={"Game Config","Sound Config", "Relay Test", "Auto Test" };
    const char* GAME_TIME="Game Time:";
    const char* BOMB_TIME="Bomb Time:";
    const char* ZERO_MINUTES="00 minutes";
    const char* ARM_TIME="Arm Time:";
    const char* ZERO_SECS="00 seconds";
    const char* ENABLE_SOUND="Enable Sound?";
    const char* YES_OR_NOT="A : Yes B : No";
    const char* ENABLE_RELAYPIN="Enable Relay?";
    const char* ENABLE_CODE="Enable Code Arm?";
    const char* GAME_TIME_TOP="GAME TIME";
    const char* ARMING_BOMB = "ARMING BOMB";
    const char* ENTER_CODE = "Enter Code";
    const char* CODE_ERROR = "Code Error!";
    const char* BOMB_ARMED = "BOMB ARMED";
    const char* DETONATION_IN = "DETONATION IN";
    const char* DISARMING = "DISARMING BOMB" ;
    const char* DISARM = "DISARMING";
    const char* GAME_OVER = " GAME OVER! ";
    const char* DEFENDERS_WIN = " DEFENDERS WIN ";
    const char* SABOTAGE_FAIL= "SABOTAGE FAIL!";




    //LiquidCrystal_I2C lcd(0x38,16,2);
    LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
    const byte ROWS = 4; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
    {'1','2','3','a'}
    ,
    {'4','5','6','b'}
    ,
    {'7','8','9','c'}
    ,
    {'*','0','#','d'}
    };

    byte rowPins[ROWS] = {
    12, 13, A5, A4}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {
    A3, A2, A1, A0
    }; //connect to the column pinouts of the keypad

    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

    char codeInput[8];
    byte time[4];
    boolean refresh=true;//1 refresh one time...
    char password[8];
    int key=-1;
    char lastKey;
    char var;
    boolean passwordEnable=false;

    //Buttons for lcd shield
    char BT_RIGHT = '4';
    char BT_UP = 'a';
    char BT_DOWN = 'b';
    char BT_LEFT = '6';
    char BT_SEL = 'd'; // Ok key
    char BT_CANCEL = 'c';
    char BT_DEFUSER = 'x'; // not implemented

    //leds

    const int REDLED = 11;
    const int GREENLED = 10;
    //const int BLUELED = 12;
    //RELAYPIN
    boolean relayEnable = false;
    const int RELAYPIN = 9;
    //IS VERY IMPORTANT THAT YOU TEST THIS TIME. BY DEFAULT IS IN 1 SEC. THAT IS NOT TOO MUCH. SO TEST IT!
    const int RELAY_TIME = 5000;

    //TIME INTS
    int GAMEHOURS = 0;
    int GAMEMINUTES = 45;
    int BOMBMINUTES = 4;
    int ACTIVATESECONDS = 5;

    boolean endGame = false;

    boolean sdStatus = false; //search and destroy game enable used in config
    boolean saStatus = false; //same but SAbotaghe
    boolean doStatus = false; //for DEmolition
    boolean start = true;
    boolean defusing;
    boolean cancelando;
    // SOUND TONES
    boolean soundEnable = true;
    int tonepin = 8; // Pin 13 for the sound
    int alarmTone1 = 700;
    int alarmTone2 = 2600;
    int activeTone = 1330;
    int errorTone = 100;

    unsigned long iTime;
    unsigned long timeCalcVar;
    unsigned long redTime;
    unsigned long greenTime;
    unsigned long iZoneTime;//initial time for zone
    byte team=0; // 0 = neutral, 1 = green team, 2 = red team

    void setup(){
    lcd.begin(16, 2);
    Serial.begin(9600);
    lcd.setCursor(3,0);
    tone(tonepin,2400,30);
    lcd.print("BLUECORE TECH");// you can add your team name or someting cool
    lcd.setCursor(0,1);
    lcd.print(" AIRSOFT BOMB");// you can add your team name or someting cool
    keypad.setHoldTime(50);
    keypad.setDebounceTime(50);
    keypad.addEventListener(keypadEvent);

    //PinModes
    pinMode(GREENLED, OUTPUT);
    pinMode(REDLED, OUTPUT);
    pinMode(RELAYPIN, OUTPUT);
    // CONFIGURE THE BARS OF PROGRESS BAR
    byte bar1[8] = {
    B10000,
    B10000,
    B10000,
    B10000,
    B10000,
    B10000,
    B10000,
    B10000,
    };
    byte bar2[8] = {
    B11000,
    B11000,
    B11000,
    B11000,
    B11000,
    B11000,
    B11000,
    B11000,
    };
    byte bar3[8] = {
    B11100,
    B11100,
    B11100,
    B11100,
    B11100,
    B11100,
    B11100,
    B11100,
    };
    byte bar4[8] = {
    B11110,
    B11110,
    B11110,
    B11110,
    B11110,
    B11110,
    B11110,
    B11110,
    };
    byte bar5[8] = {
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    };
    byte up[8] = {
    B00000,
    B00100,
    B01110,
    B11111,
    B11111,
    B00000,
    B00000,
    };

    byte down[8] = {
    B00000,
    B00000,
    B11111,
    B11111,
    B01110,
    B00100,
    B00000,
    };
    lcd.createChar(0,bar1);
    lcd.createChar(1,bar2);
    lcd.createChar(2,bar3);
    lcd.createChar(3,bar4);
    lcd.createChar(4,bar5);
    lcd.createChar(5,up);
    lcd.createChar(6,down);
    }

    void loop(){
    menuPrincipal();
    }
    void keypadEvent(KeypadEvent key){
    switch (keypad.getState()){
    case RELEASED:
    switch (key){
    case 'd': defusing=false;
    break;
    case 'c': cancelando=false;
    break;
    }
    break;
    case HOLD:
    switch (key){
    case 'd': defusing= true;
    break;
    case 'c': cancelando=true;
    break;
    }
    break;
    }
    }




    //##################MENUS###############################

    void menuPrincipal(){ //MAIN MENU

    digitalWrite(GREENLED, LOW);
    digitalWrite(REDLED, LOW);

    // if whe start a new game from another we need to restart propertly this variables
    saStatus=false;
    sdStatus=false;
    doStatus=false;
    //Draw menu
    cls();//clear lcd and set cursor to 0,0
    int i=0;
    // HERE YOU CAN ADD MORE ITEMS ON THE MAIN MENU
    lcd.print(menu1[i]);
    lcd.setCursor(15,1);
    checkArrows(i,2);
    while(1){

    var = keypad.waitForKey();
    if(var == BT_UP && i>0){
    tone(tonepin,2400,30);
    i--;
    cls();
    lcd.print(menu1[i]);
    checkArrows(i,2);
    delay(50);
    }
    if(var == BT_DOWN && i<2){
    tone(tonepin,2400,30);
    i++;
    cls();
    lcd.print(menu1[i]);
    checkArrows(i,2);
    delay(50);
    }

    if(var == BT_SEL){
    tone(tonepin,2400,30);
    cls();
    switch (i){

    case 0:
    sdStatus=true;
    configQuickGame();
    startGameCount();
    search();
    break;
    case 1:
    saStatus=true;
    configQuickGame();
    startGameCount();
    sabotage();
    break;
    case 2:

    doStatus=true;
    configQuickGame();
    startGameCount();
    domination();
    break;
    case 3:
    config();
    break;

    }
    }
    }
    }

    void config(){
    //Draw menu
    lcd.clear();
    lcd.setCursor(0, 0);
    int i=0;

    delay(500);
    lcd.print(menu2[i]);
    checkArrows(i,3);

    while(1){
    var=keypad.waitForKey();
    if(var == BT_UP && i>0){
    tone(tonepin,2400,30);
    i--;
    lcd.clear();
    lcd.print(menu2[i]);
    checkArrows(i,3);
    delay(50);

    }
    if(var == BT_DOWN && i<3){
    tone(tonepin,2400,30);
    i++;
    lcd.clear();
    lcd.print(menu2[i]);
    checkArrows(i,3);
    delay(50);
    }
    if(var == BT_CANCEL){
    tone(tonepin,2400,30);
    menuPrincipal();
    }
    if(var == BT_SEL){
    tone(tonepin,2400,30);
    lcd.clear();
    switch (i){

    case 0:
    //gameConfigMenu();
    break;

    case 1:
    //soundConfigMenu();
    break;

    case 2:
    cls();
    lcd.print("RELAYPIN ON!");
    digitalWrite(RELAYPIN, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(4000); // wait for 4 second
    cls();
    lcd.print("RELAYPIN OFF!");
    digitalWrite(RELAYPIN, LOW);
    delay(2000);
    config();
    break;

    }
    }
    }
    }

    void configQuickGame(){

    cls();
    //GAME TIME
    if(sdStatus || doStatus || saStatus){
    menu1:
    cls();
    lcd.print(GAME_TIME);
    delay(100);
    lcd.setCursor(0,1);
    lcd.print("00:00 hh:mm");
    lcd.cursor();
    lcd.blink();
    lcd.setCursor(0,1);
    byte var2=0;
    for(int i=0;i<4;i++){
    while(1){
    if(i==2 && var2==0){
    lcd.print(":");
    var2=1;
    }

    byte varu= getRealNumber();
    if(varu !=11){

    time[i] = varu;
    Serial.print(varu);


    lcd.print(varu);
    tone(tonepin,2400,30);

    break;
    }
    }
    }
    lcd.noCursor();
    lcd.noBlink();
    lcd.setCursor(13,1);
    lcd.print("ok?");
    //zona donde pasamos los items a
    //redibujar
    while(1){
    var = keypad.waitForKey();
    if(var == 'd') // Accept
    {
    tone(tonepin,2400,30);
    GAMEMINUTES= ((time[0]*600)+(time[1]*60)+(time[2]*10)+(time[3]));
    break;
    }
    if(var == 'c') // Cancel or Back Button :')
    {
    tone(tonepin,2400,30);
    goto menu1;
    }
    }
    tone(tonepin,2400,30);
    cls();
    }
    //BOMB TIME
    if(sdStatus || saStatus){

    menu2:
    cls();
    lcd.print(BOMB_TIME);
    delay(100);
    lcd.setCursor(0,1);
    lcd.print(ZERO_MINUTES);
    lcd.cursor();
    lcd.blink();
    lcd.setCursor(0,1);
    for(int i=0;i<2;i++){
    while(1){
    byte varu= getRealNumber();
    if(varu !=11){
    time[i] = varu;
    lcd.print(varu);
    tone(tonepin,2400,30);
    break;
    }
    }
    }
    lcd.noCursor();
    lcd.noBlink();
    lcd.setCursor(13,1);
    lcd.print("ok?");
    //zona donde pasamos los items a
    //redibujar
    while(1){
    var = keypad.waitForKey();
    if(var == 'd') //
    {
    tone(tonepin,2400,30);
    BOMBMINUTES= ((time[0]*10)+(time[1]));
    break;
    }
    if(var == 'c') // Cancel or Back Button :')
    {
    tone(tonepin,2400,30);
    goto menu2;
    }
    }
    tone(tonepin,2400,30);
    cls();
    }
    cls();
    //ARMING TIME
    if(sdStatus || doStatus || saStatus){

    menu3:
    cls();
    lcd.print(ARM_TIME);
    delay(100);
    lcd.setCursor(0,1);
    lcd.print(ZERO_SECS);
    lcd.cursor();
    lcd.blink();
    lcd.setCursor(0,1);
    for(int i=0;i<2;i++){
    while(1){
    byte varu= getRealNumber();
    if(varu !=11){
    time[i] = varu;
    lcd.print(varu);
    tone(tonepin,2400,30);
    break;
    }
    }
    }
    lcd.noCursor();
    lcd.noBlink();
    lcd.setCursor(13,1);
    lcd.print("ok?");

    //zona donde pasamos los items a
    //redibujar
    while(1){
    var = keypad.waitForKey();
    if(var == 'd') // Accept
    {
    tone(tonepin,2400,30);
    ACTIVATESECONDS= ((time[0]*10)+(time[1]));
    break;
    }
    if(var == 'c') // Cancel or Back Button :')
    {
    tone(tonepin,2400,30);
    goto menu3;
    }
    }
    tone(tonepin,2400,30);
    cls();
    }
    //sound??
    if(sdStatus || saStatus || doStatus){
    cls();
    lcd.print(ENABLE_SOUND);
    lcd.setCursor(0,1);
    lcd.print(YES_OR_NOT);

    while(1)
    {
    var = keypad.waitForKey();
    if(var == 'a' ){
    soundEnable=true;
    tone(tonepin,2400,30);
    break;
    }

    if(var == 'b' ){
    soundEnable=false;
    tone(tonepin,2400,30);
    break;
    }
    }
    }
    //Activate RELAY at Terrorist game ends??? Boom!

    if(sdStatus || saStatus){
    cls();
    lcd.print(ENABLE_RELAYPIN);
    lcd.setCursor(0,1);
    lcd.print(YES_OR_NOT);
    while(1)
    {
    var = keypad.waitForKey();
    if(var == 'a' ){
    relayEnable=true;
    tone(tonepin,2400,30);
    break;
    }
    if(var == 'b' ){
    relayEnable=false;
    tone(tonepin,2400,30);
    break;
    }
    }
    }
    //You Want a password enable-disable game?
    if(sdStatus || saStatus){
    cls();
    lcd.print(ENABLE_CODE);
    lcd.setCursor(0,1);
    lcd.print(YES_OR_NOT);

    while(1)
    {
    var = keypad.waitForKey();
    if(var == 'a' ){
    tone(tonepin,2400,30);
    setNewPass();
    passwordEnable = true;
    break;
    }
    if(var == 'b' ){
    tone(tonepin,2400,30);
    passwordEnable = false;
    break;
    }
    }
    tone(tonepin,2400,30);
    }
    //Continue the game Very Happy
    }

    void domination(){

    //SETUP INITIAL TIME
    int minutos = GAMEMINUTES-1;
    boolean showGameTime=true;
    unsigned long a;
    unsigned long iTime=millis(); // initialTime in millisec
    unsigned long aTime;

    team=0;
    iZoneTime=0;
    aTime=0;
    redTime=0;
    greenTime=0;

    int largoTono = 50;
    // 0 = neutral, 1 = green team, 2 = red team
    a=millis();
    //Starting Game Code
    while(1) // this is the important code, is a little messy but works good.
    {
    if(endGame){
    gameOver();
    }

    keypad.getKey();
    aTime=millis()- iTime;
    //Code for led blinking
    timeCalcVar=(millis()- iTime)%1000;
    if(timeCalcVar >= 0 && timeCalcVar <= 40)
    {
    if(team==1)digitalWrite(GREENLED, HIGH);
    if(team==2)digitalWrite(REDLED, HIGH);
    }
    if(timeCalcVar >= 50 && timeCalcVar <= 100)
    {
    if(team==1)digitalWrite(GREENLED, LOW);
    if(team==2)digitalWrite(REDLED, LOW);
    }
    // Sound!!! same as Destroy
    if(timeCalcVar >= 0 && timeCalcVar <= 40 && soundEnable)tone(tonepin,activeTone,largoTono);

    if(timeCalcVar >= 245 && timeCalcVar <= 255 && minutos-aTime/60000<2 && soundEnable)tone(tonepin,activeTone,largoTono);
    if(timeCalcVar >= 495 && timeCalcVar <= 510 && minutos-aTime/60000<4 && soundEnable)tone(tonepin,activeTone,largoTono);
    if(timeCalcVar >= 745 && timeCalcVar <= 760 && minutos-aTime/60000<2 && soundEnable)tone(tonepin,activeTone,largoTono);
    //Help to count 3 secs
    if(a+2000 a=millis();
    showGameTime=!showGameTime;
    cls();
    }
    //THE NEXT TO METHODS SHOW "GAME TIME" AND "CONTROLED ZONE TIME" IT SHOWS 2 AND 2 SEC EACH

    if(showGameTime){ //THE SECOND IS /2
    lcd.setCursor(3,0);
    lcd.print("GAME TIME");
    lcd.setCursor(3,1);
    printTime(minutos, aTime);
    }
    else if (!showGameTime){

    lcd.setCursor(2,0);
    if(team == 0)lcd.print("NEUTRAL ZONE");
    if(team == 1)lcd.print(" GREEN ZONE");
    if(team == 2)lcd.print(" RED ZONE");

    if(team>0){
    lcd.setCursor(3,1);
    printTimeDom(millis()-iZoneTime,true);
    }
    }

    Quelqu'un voit quelque chose ?

    Merci à vous Smile

    astur

    Messages : 14
    Date d'inscription : 10/11/2017

    Re: Projet Valise multi mode

    Message par astur le Ven 10 Nov - 15:06

    Je précise que même en passant sur mon lcd key shield V1.2 et en passant sur la lib lcd classique ça ne fonctionne pas Sad

    Test effectué sur arduino uno et mega.

    ++ Smile


    EDIT :

    J'ai reussi en passant par la librairie : #include

    Je peux donc passer à l'étape supérieur ! Smile

      La date/heure actuelle est Mer 20 Juin - 3:28