ALANNA MANFREDINI'S DESIGN KITCHEN
  • Home
  • About
  • Machine Learning
  • Robotics
  • PINBALL MACHINE
  • DESIGN
  • Math

PINBALL MACHINE

Initial Electronics

12/15/2022

0 Comments

 
I created the initial code for the most important electrical components. 

This code was made as a proof of concept and includes delays, which will not be used once all of the code segments are integrated. 

The aim of the flipper code is to do the aforementioned switch between 50V and 5V with PWM. All the bumpers and slingshots will be controlled with almost identical code. The lights flash in order once the points are greater than a certain value (not included in this code). Every time the ball rolls over a switch, a certain number of points are added to the point tally. Finally the display writes these points on an LCD display. 

In future I will combine all this code into one block that runs through each loop.  

Electrical Schematics

Picture
Various circuits

Arduino Electrical Schematic

Picture
Picture
Arduino circuits

Code

Attached is the functional code for the flippers, the lights, the point calculators, and the display.

Flipper PWM


#include <time.h>


int solenoidPin = 6;
int button = 2;
bool pushed = LOW;
int lengthFlipperMaxActuated = 500;
int LFlipperPushed;

void setup() {
  pinMode(solenoidPin,OUTPUT);
  pinMode(button, INPUT);
  Serial.begin(9600);

  Serial.println("Push button Test");
}

void loop() 
{
  analogWrite(solenoidPin, 0);
  if(digitalRead(button) == pushed)
  {

    //Serial.println(pushed);
    //turn the solenoid onto actuation "high volt" value
    analogWrite(solenoidPin, 220);
    Serial.println(LFlipperPushed);
    delay(500);
    //immediately drop to "low volt" value while the solenoid is still being held

    Serial.println(digitalRead(button));
    while(digitalRead(button) != 1)
    {
      analogWrite(solenoidPin,50);
      delay(10); //idk why i have to have this, else the value must fluctuate - try removing once soldered
    }
    //Serial.println("here");
  }
  
}

Three Light Flash

// C++ code
//

int GreenLED = A5;
int YellowLED = A4;
int RedLED = A3;


void setup()
{
  pinMode(GreenLED,OUTPUT);
  pinMode(YellowLED,OUTPUT);
  pinMode(RedLED,OUTPUT);
  
  digitalWrite(GreenLED,LOW);
  digitalWrite(YellowLED,LOW);
  digitalWrite(RedLED,LOW);
  
  Serial.begin(9600);
}

void loop()
{
  //NOTE corrected order
  //Go Mode
  goMode();
  
  //Yield Mode
  yieldMode();
  
  
  //Stop Mode
  stopMode();
  
  
}

void goMode(){
  digitalWrite(GreenLED,HIGH);
  digitalWrite(YellowLED,LOW);
  digitalWrite(RedLED,LOW);
  

  Serial.println(" Light Mode : Go ");
  delay(200); // Wait for 1000 millisecond(s)
}

void yieldMode(){
  digitalWrite(GreenLED,LOW);
  digitalWrite(YellowLED,HIGH);
  digitalWrite(RedLED,LOW);
  

  Serial.println(" Light Mode : Yield ");
  delay(200); // Wait for 1000 millisecond(s)
}

void stopMode(){
  digitalWrite(GreenLED,LOW);
  digitalWrite(YellowLED,LOW);
  digitalWrite(RedLED,HIGH);
  

  Serial.println(" Light Mode : Stop ");
  delay(200); // Wait for 1000 millisecond(s)
}

Sensor Switches


#include <time.h>


int button = 4;
bool pushed = LOW;

void setup() {
  pinMode(button, INPUT);
  Serial.begin(9600);

  Serial.println("Push button Test");
}

void loop() 
{

  if(digitalRead(button) == LOW)
  {
    Serial.println("push");

    }

  }
  

Display

/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  //lcd.print(millis() / 1000);
}

0 Comments



Leave a Reply.

    Alanna Manfredini

    A blog of my progress and process of making a Pinball Machine

Site powered by Weebly. Managed by Porkbun
  • Home
  • About
  • Machine Learning
  • Robotics
  • PINBALL MACHINE
  • DESIGN
  • Math