Question

In: Computer Science

Using an Arduino MEGA write the code for the following problem. You have a pinball machine...

  1. Using an Arduino MEGA write the code for the following problem.

You have a pinball machine with four switches on the playboard. When a ball rolls over one of the switches that action must trigger the Arduino to add 20 points to the score being displayed on a 16x4 LCD, and actuate a relay that will trigger a bumping solenoid elsewhere on the board. The solenoid should return to home after the switch is no longer depressed by the ball.

Hint: treat the roll over switches like limit switches.

Solutions

Expert Solution

Arduino program for above problem:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define sw1 2
#define sw2 3
#define sw3 4
#define sw4 5
#define so1 6

//variable to store points of game
int points = 0;

void setup() {

  //setting pinmode of switches
  pinMode(sw1, INPUT);
  pinMode(sw2, INPUT);
  pinMode(sw3, INPUT);
  pinMode(sw4, INPUT);

  //seting pinmode of solenoid
  pinMode(so1, OUTPUT)
  
  //Setting the baud rate
  Serial.begin(9600);

  // setting column and row no.s in LCD
  lcd.begin(16, 4);

  //setting staring position in 16 X 4 lcd
  lcd.setCursor(1, 2)

  //printing initial score 
  lcd.print("score: 0");

}

//Lets assume we have pull up switches 
//that means arduino will read high when switch is pressed

void loop() {

    //if any switch is pressed by the pinball 
    if(digitalRead(sw1) == HIGH || digitalRead(sw2) == HIGH || digitalRead(sw3) == HIGH || digitalRead(sw4) == HIGH)
    {

      //increment the points by 20
      points += 20;

      //trigger a bumping solenoid, so1
      digitalWrite(so1, HIGH);

      //clear the lcd first
      lcd.clear();

     //show the points on lcd
     lcd.print("Score: " + String(sol));

    }
      
    //if none of the switches is pressed
    else{
       //off the solenoid so that it comes abck to home, so1
       digitalWrite(so1, HIGH);
        
     }

    

}

if it helps you, do upvote as it motivates us a lot!


Related Solutions

Write code using the Arduino IDE that compiles with no errors. 2-bit adder: The code must...
Write code using the Arduino IDE that compiles with no errors. 2-bit adder: The code must read two digital input signals and turn on two LEDS as needed to show the sum of the inputs. e.g. 0 + 1 = 01.
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following...
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following conditions: For night conditions, turn on white LED 1 For day conditions, turn off white LED 1 Code should check intervals every 5 seconds. NEED THE BELOW CODE TO FIT THE ABOVE REQUIREMENTS. const int lightSensor = 5; //light sensor variable float sensValue = 0; //variable to hold sensor readings const int button = 3; //pin for button reads const int LED1 = 5;...
write the code of 4 digit 7-segment display using arduino uno in assembly language by using...
write the code of 4 digit 7-segment display using arduino uno in assembly language by using software AVR STUDIO 5.1?
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
Using Arduino to blink an LED in morse code. Morse code is used as one of...
Using Arduino to blink an LED in morse code. Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot : raw data, delay data (int) Purpose: Delay Block (**Using Class**) Input : u(t) Output : o(t)=u(t-h) sample time=0.02 Delay (h) = 0.4
arduino c code only write a code that counts down a timer on serial monitor and...
arduino c code only write a code that counts down a timer on serial monitor and if A1 is typed into serial monitor prints the timer counting down and writes at 1 second hello and at 5 secs goodbye and repeats every 5 secs A2 is typed as above at 2 seconds writes hello and 3 seconds writes goodbye A3 same as above but at 3 seconds says hello and 2 seconds goodbye This continues until c is pressed to...
Can you write an arduino code to learn Hx711 and two Strain gauge value with Half...
Can you write an arduino code to learn Hx711 and two Strain gauge value with Half wheatstone bridge?
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100...
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100 and 300. Pick a number at random out of these 50 random variables. a. Determine the probability of the chosen number being greater than 200. This may be achieved by counting the numbers that are greater than 200 and dividing the count by 50. Make sure you, i.Formulate the appropriate if-conditions to check for a number being greater than 200 ii. Use a for-loop...
Write an Arduino code that calls a web service to show the location of the iss...
Write an Arduino code that calls a web service to show the location of the iss after a couple of seconds and displays in on an LCD
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT