makerball
Published

Makerball

Makerball is a DIY pinball machine kit that can be upgraded digitally with the Arduino Genuino 101. Here we show you the electronical part.

IntermediateShowcase (no instructions)2,128
Makerball

Things used in this project

Story

Read more

Custom parts and enclosures

Connections

This image shows how to connect the wires.
Makerball starter elements exkl x3s1hx5xpx

Schematics

Schematic of the parts

This is how the parts are connected.
170512 sensors arduino schema 3 tjlt10nmor

Code

Arduino Main Code

Arduino
This code takes the signals coming from the 3 sensors and the bluetooth.
unsigned long timeMillis = 0;
unsigned long timeReset = 0;



void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
  setup_bluetooth();
  setup_sensor_a();
  setup_sensor_b();
  setup_sensor_c();
  setup_sensor_d();
}

void loop()
{
  loop_bluetooth();
}


void second_loop(){
  timeMillis = millis();
  loop_sensor_a();
  loop_sensor_b();
  loop_sensor_c();
  loop_sensor_d();
}

Arduino Bluettoth Code

Arduino
This code handles the bluetooth connection from the Genuino 101 to a smartphone.
//https://www.arduino.cc/en/Tutorial/Genuino101CurieBLEHeartRateMonitor
#include <CurieBLE.h>

int const outLED = 13; // customize name
boolean isBluetoothOnline = false;
int const maxSendValue = 255;
int const bluetoothSendDelay = 10;


BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService bleService("025A7775-49AA-42BD-BBDB-E2AE77782966"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEIntCharacteristic switchCharacteristic("F38A2C23-BC54-40FC-BED0-60EDDA139F47", BLERead | BLEWrite | BLENotify);


void setup_bluetooth() {
  pinMode(outLED, OUTPUT);   // initialize the LED on pin 13 to indicate when a central is connected

  // set advertised local name and service UUID:
  blePeripheral.setLocalName("LED");
  blePeripheral.setAdvertisedServiceUuid(bleService.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(bleService);
  blePeripheral.addAttribute(switchCharacteristic);


  // set the initial value for the characeristic:
  switchCharacteristic.setValue(0);

  // begin advertising BLE service:
  blePeripheral.begin();

  Serial.println("BLE LED Peripheral");
}


void loop_bluetooth() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      isBluetoothOnline = true;
      digitalWrite(13, isBluetoothOnline);
      second_loop();
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
    isBluetoothOnline = false;
    digitalWrite(13, isBluetoothOnline);
  }
}

void sendSensorValue(int value) {

  Serial.print("write value: ");
  Serial.println(value, DEC);


  if (value <= maxSendValue) {
    switchCharacteristic.setValue(value);
  } else {
    int loops = (int) floor(value / maxSendValue);
    int modulo = (int) value % maxSendValue;

    for (int i = 0; i < loops; i++) {
      switchCharacteristic.setValue(maxSendValue);
      delay(bluetoothSendDelay);
    }
    if (modulo != 0) {
      switchCharacteristic.setValue(modulo);
    }
  }
}

Arduino Sensor Code

Arduino
This code checks the signals from the conductive copper foils.
int const outputValueA = 0;  // customize name and value.

int const inPinA = 8; // customize name

unsigned long sensorBreakA = 5000;  // customize name
unsigned long sensorBreakTimeA = timeReset; // customize name

void setup_sensor_a() {
  pinMode(inPinA, INPUT); // customize name
  Serial.println("Setup up sensor A : done");
}



void loop_sensor_a() {
  int val = digitalRead(inPinA);  // customize name

  // prüfen, wie lange es dauert, bis er wieder eine prüfung macht
  Serial.println(millis(), DEC);

  // prüfen, wie lange sensor berührt wird
  if (val == 1){
    Serial.println(millis(), DEC);
  }

  if (sensorBreakTimeA == timeReset && val == 1) { // customize name
    sensorBreakTimeA = timeMillis + sensorBreakA; // customize name
    Serial.print("send value : ");
    Serial.println(outputValueA, DEC);
    sendSensorValue(outputValueA);
  } else if (sensorBreakTimeA > timeMillis) { // customize name
    //Serial.println("break :  A");             // customize name
  } else if (sensorBreakTimeA < timeMillis) { // customize name
    sensorBreakTimeA = timeReset;             // customize name
    //Serial.println(val, DEC);
  }
}

Credits

makerball

makerball

0 projects • 0 followers
Contact

Comments