Hi,
I'm new to programming and would be very grateful if someone could look at my code and tell me what I'm doing wrong
Project.ino (3.91 KB)
Hi,
I'm new to programming and would be very grateful if someone could look at my code and tell me what I'm doing wrong
Project.ino (3.91 KB)
(deleted)
Compiles for me (1.0)
int hundredsLatch = 5;
int thousandsLatch = 6;
int tenthousandsLatch = 7;
int JKreset = 4;
//Data Pins
int A=8;
int B=9;
int C=10;
int D=11;
//Input signals
int signalOne = 3;
void setup() {
// put your setup code here, to run once:
pinMode(hundredsLatch,OUTPUT);
pinMode(thousandsLatch, OUTPUT);
pinMode(tenthousandsLatch, OUTPUT);
pinMode(JKreset,OUTPUT);
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
pinMode(signalOne,INPUT);
Serial.begin(9600);
//reset the FlipFlop OUTPUT Pin4 arduino -see latch
digitalWrite(JKreset,HIGH);
delay(100);
digitalWrite(JKreset,LOW);
//Load the Display with zeros
display1(0);
//Measure the pulse using pulseIn see reference
//unsigned int duration= pulseIn(signalOne,20000000);//?? see reference
unsigned int duration= 21300;
double duration2 = (double)duration;
display1(duration);
delay(5000);
double angularVelocity;
double theta = PI/4.0; // Pi is double so denominator has to be double
// Calulate the anglerVelocity in Rads/s using pi/4 for angle.
duration2 = (double)duration2/10000000.0;
angularVelocity = theta/duration2;
display1(angularVelocity);
Serial.println(angularVelocity);
}
void display1(unsigned int duration1){ //Displays first three significant of a five digit Decimal No. on a 3 digit 7 segment Display.
//Declaration of variables local to display1 function
byte units;
byte tens;
byte hundreds;
byte thousands;
byte tenthousands;
tenthousands = duration1/10000;
duration1 = duration1%10000;
thousands = duration1/1000;
duration1 = duration1%1000;
hundreds = duration1/100;
duration1=duration1%100;
tens = duration1/10;
duration1 = duration1%10;
units = duration1;
//***********************************************************
//Conversion of duration to five discrete BCD variables
decimalToBCD(tenthousands);
digitalWrite(tenthousandsLatch,HIGH);
delay(100);
digitalWrite(tenthousandsLatch,LOW);
decimalToBCD(thousands);
digitalWrite(thousandsLatch,HIGH);
delay(100);
digitalWrite(thousandsLatch,LOW);
decimalToBCD(hundreds);
digitalWrite(hundredsLatch,HIGH);
delay(100);
digitalWrite(hundredsLatch,LOW);
//***********************************************************
//Display the required digits
//Test using Serial Monitor
Serial.print("*");
Serial.print(tenthousands);
Serial.print("*");
Serial.print(thousands);
Serial.print("*");
Serial.print(hundreds);
//Etc
Serial.println("*");
}
void decimalToBCD(int number){
if(number/8 ==1){
digitalWrite (D,HIGH);
}else{
digitalWrite (D,LOW);
}
number = number%8; // after this line, number should be between 0-7
if (number/4==1){
digitalWrite(C,HIGH);
}else {
digitalWrite(C,LOW);
}
number = number%4;
if (number/2==1){
digitalWrite(B,HIGH);
}else {
digitalWrite(B,LOW);
}
number = number%2;
if (number/1==1){
digitalWrite(A,HIGH);
}else {
digitalWrite(A,LOW);
}
}
void loop() {
// put your main code here, to run repeatedly:
// not used in this program
}
Yeah that's what has me so confused because it worked fine for me today in school but it won't work for me at home on my own board (It's a geekcreit board)
donegaci:
(It's a geekcreit board)
A what?
(deleted)
(deleted)