newproyecto
Published © GPL3+

Spaceship command

A good pilot needs the controls of his ship and here they are.

IntermediateFull instructions provided1 hour297
Spaceship command

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×11
Male/Male Jumper Wires
×6
Resistor 10k ohm
Resistor 10k ohm
×2
Resistor 221 ohm
Resistor 221 ohm
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Scheme

Code

Code

Arduino
#include <Wire.h>                 
#include <LiquidCrystal_I2C.h>  //libraries for lcd

LiquidCrystal_I2C lcd(0x27,16,2); 
#define joyX A0
#define joyY A1
int btn1 = 10;
int btn2 = 11;
int led1 = 13;
int led2 = 12;
void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(btn1, INPUT);
  pinMode(btn2, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  lcd.init();                     
  lcd.backlight();
}
void loop() {
   int xValue = analogRead(joyX);
   int yValue = analogRead(joyY);
   if (xValue>=500 && yValue>=1020){
  lcd.setCursor(0,0);
  lcd.print("to the left");
  delay(2000);
  lcd.clear();
  }
  else if (xValue>=0 && yValue<=10)
  {
    lcd.setCursor(0,0);
    lcd.print("to the right");
    delay(2000);
    lcd.clear();
  }
   else if (digitalRead(btn1)==HIGH){
    lcd.setCursor(0,0);
    lcd.print("shooting");
    lcd.setCursor(0,1);
    lcd.print("laser beams");
    digitalWrite(led1,HIGH);
    delay(2000);
    lcd.clear();
    digitalWrite(led1,LOW);
  }
   else if (digitalRead(btn2)==HIGH){
   lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:9");
     lcd.setCursor(0,0);
     delay(1000);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:8");
     lcd.setCursor(0,0);
     delay(1000);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:7");
     delay(1000);
     lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:6");
     delay(1000);
     lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:5");
     delay(1000);
     lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:4");
     delay(1000);
     lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:3");
     delay(1000);
     lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:2");
     delay(1000);
     lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:1");
     delay(1000);
     lcd.setCursor(0,0);
     lcd.print("activating");
     lcd.setCursor(0,1);
     lcd.print("hyperspace in:0");
     delay(1000);
     lcd.clear();
      digitalWrite(led2,HIGH);
     delay(7000);
     digitalWrite(led2,LOW);
   }
  else{
    digitalWrite(13, LOW);
    digitalWrite(12, LOW);  
  }
}

Credits

newproyecto
3 projects • 4 followers
Hello everyone, my name is Antonio and I love programming and doing projects with Arduino and I hope these projects will help you.
Contact

Comments

Please log in or sign up to comment.