Hi

This is my first time programing on 4D system and need practice in arduino. I am making an E-bike and i wanted to use 4D to make interface; speedometer, battery level, change between different running modes for the DC motor. I am using GEN4-ULCD24PT screen. Please find attach a picture of the interface that i plan to us and the programming below. I have written next to which "if" i need the win button to activite but i cant figure out how to do that. I am not sure if have done the programming for the information going out correctly.

The program none related parts to 4D system is almost finished complete, just requires another hall sensor for activation purpose only - need to figure out how to do that but the rest should be okay.

Any help with any of these problem would be great - i am restruggling with the 4D to arduino on the arduino side.



//pin in use Battery sensor A2, hall sensor for MPH pin 2, screen inputs reset pin 4 - pin 1 and 0 for TXD RXD.
// pin for motor - enA 9, in1 6, in2 7
// brake input – pin 10 11

#include <genieArduino.h>

Genie genie;

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period=1;
int magnetsense=0;
int laststate=1;
int rotDirection = 0;
int pressed = false;
int RightBrake = 10;
int LeftBrake = 11;

int sensPin=2;
int counter=0;
int analogInput = A1;
int value = 0;

#define RESETLINE 4
#define enA 9
#define in1 6
#define in2 7

float bikespeed;
float MPH;
float circumference= 0.44625;
float volt = 0.0;
float voltper = 0.0;



void setup() {
Serial.begin(9600);

genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display

// stuff related to screen start
pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
digitalWrite(RESETLINE, 1); // Reset the Display via D4
delay(100);
digitalWrite(RESETLINE, 0); // unReset the Display via D4

delay (3500); //let the display start up after the reset (This is important)
genie.WriteContrast (1);
genie.WriteStr (0, GENIE_VERSION);

// stuff related to screen end

pinMode(analogInput, INPUT);
startMillis=millis();
pinMode(sensPin, INPUT);

//brake set up
pinMode(RightBrake, INPUT);
pinMode(LeftBrake, INPUT);

// Motor setup start
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
// Set initial rotation direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
// Motor setup end

}


void loop() {

beginningloop:

// start of voltage reading
value = analogRead(0);
volt = (((value) * (5.0)) / (1024.0)) / (7500) / ((3000) + (7500)) ; // calculation for voltage
voltper = ((volt) / (24)) * (100); // voltage reading to battery
genie.WriteObject (GENIE_OBJ_GAUGE, 0x00, voltper) ;
// end of voltage reading

// start of speed reading
currentMillis=millis();
magnetsense=digitalRead(sensPin);

if(magnetsense==0 && laststate==1){
laststate=0;

if(currentMillis-startMillis>=period && laststate==0){
bikespeed=circumference/(currentMillis-startMillis)*1000;
startMillis=currentMillis;
counter++;
MPH = bikespeed*3600;
}
}
else{
if(currentMillis-startMillis>=period && laststate==0){
startMillis=currentMillis;
laststate=1;
}
}

genie.WriteObject (GENIE_OBJ_COOL_GAUGE, 0x00, MPH ) ;
genie.WriteObject (GENIE_OBJ_LED_DIGITS, 0x00, MPH ) ;
// end of speed reading

//Start of motor control program
if ((digitalRead(RightBrake) == HIGH) or (digitalRead(LeftBrake) ==HIGH)) { // braking system
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
rotDirection = 0;
goto beginningloop;
}

if (voltper<10) { //battery to low
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
rotDirection = 0;
goto beginningloop;
}

if () { // if input from winbutton 0, normal run mode
if (MPH>35) { //slow down speed
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
rotDirection = 0;
goto beginningloop;
}

if (voltper<20) {
int potValue = analogRead(A0); // Read potentiometer value
int pwmOutput = (map(potValue, 0, 1023, 0 , 255)/2); // Map the potentiometer value from 0 to 255
analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
goto beginningloop;
}

int potValue = analogRead(A0); // Read potentiometer value
int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
}

if () { // if input from winbutton 1, reverse mode
if (MPH>3) { //slow down speed
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
rotDirection = 0;
goto beginningloop;
}

int potValue = analogRead(A0); // Read potentiometer value
int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
rotDirection = 1;
}

if () { // if input from winbutton 2, test limit mode

int potValue = analogRead(A0); // Read potentiometer value
int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
}
//End of motor control program

}
Attached Files