something like a simple if I1 is high add1 if I2 is high add 2 and so on
and for output
if BCD number is 10 -> output 8 high (latch until reboot or a new BCD number shows up)
the BCD numbers come from a CNC machine from the 1980s and is convertig M commands to BCD and I want to add a simple extension so you can use all M commands to do things.,..
oh and is a thruthtable possible ? highest M umber is 99 lowest is 1
serial monitor output of the BCD numbers would be fine - but only if it changes, no flooding
can someone draw me an example ? that should be not that much of code but I dont know where to start
my lack of programming needs to be fixed - this is where I start :)))
If you can spend an 8 bit port and connect the inputs to that port in the right sequence then you can read the result without any further calculation. The same for an output port.
It's BCD, so yes, you can grab all the bits, but then you need a simple conversion from a byte holding two BCD digits to an integer be it byte or int or whatever, which would be 0..99.
int theNumber = (10 * ((in & 0xf0) / 16)) + (in & 0xf);
I know what setup and void is but then things get complicated,...
I can read what code does and kinda understand it nut cant write it - so basicly a total n00b
before I start to copy together and you guys need to correct it several times, can someone PLEASE stitch together the full program?
I know thats your free time guys! and I also know that this here is no programming service, but in sake of time and energy from you guys telling me several times what I did wrong I think its faster if someone can PLEASE stitch it together, and I try to modify it by myself,..
sorry for that kinda question, I know you have beter things to do and I could now invest a couple hours to get where I'm able but you know - its easier to understand for me on an example..
this is what i could make
pinMode(0, INPUT); // signal comming in
pinMode(1, INPUT); // signal 1
pinMode(2, INPUT); // signal 2
pinMode(3, INPUT); // signal 4
pinMode(4, INPUT); // signal 8
pinMode(5, INPUT); // signal 10
pinMode(6, INPUT); // signal 20
pinMode(7, INPUT); // signal 40
pinMode(8, INPUT); // signal 80
pinMode(9, OUTPUT); // output for Mxx SIGNAL
int BCDnum = 0; // for incoming BCD data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
int BCDnum = I1*1 + I2*2 + I3*4 +I4*8 + I5*10 + I6*20 +I7*40 +I8*80;
if (BCDnum > 0 && I0 >= 1) {
// say what you got:
Serial.print("I received: ");
Serial.println(BCDnum, DEC);
if(BCDnum =21){
digitalWrite(9, HIGH); // sets the digital pin 13 on
}
}
ok, I got a bit further, but it is still not working
I should not use I0 and I1 when working with serial right?
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(0, INPUT); // BCD number coming in
pinMode(1, INPUT); // BCD number
pinMode(2, INPUT); // BCD number
pinMode(3, INPUT); // BCD number
pinMode(4, INPUT); // BCD number
pinMode(5, INPUT); // BCD number
pinMode(6, INPUT); // BCD number
pinMode(7, INPUT); // BCD number
pinMode(8, INPUT); // BCD number
pinMode(11, OUTPUT); // sets the digital pin 9 as output
}
void loop() {
int I0;
I0 = digitalRead(2);
int I1;
I0 = digitalRead(3);
int I2;
I0 = digitalRead(4);
int I3;
I0 = digitalRead(5);
int I4;
I0 = digitalRead(6);
int I5;
I0 = digitalRead(7);
int I6;
I0 = digitalRead(8);
int I7;
I0 = digitalRead(9);
int I8;
I0 = digitalRead(10);
int BCDnum = 0;
if (I0 = HIGH){
int BCDnum = I1*1 + I2*2 + I3*4 + I4*8 + I5*10 + I6*20 + I7*40 + I8*80; //adding the BCD number up)
}
if (I0 = HIGH && BCDnum > 0 && BCDnum < 100) {
Serial.print ("BCD Number: ");
Serial.println ("BCDnum");
if (BCDnum = 21){
digitalWrite(10,HIGH);
}
}
// put your main code here, to run repeatedly:
}
Haha, right. So warnings are just that. Ignore the ones that you understand are irrelevant. Here it just calls attention to the mystery of why you make so much trouble with BCDnjm and then don't do anything with it… not even print it out.
Yes and sorry I didn't spot it with all the excitement around comparing and assigning.
The
int BCDnum
is a declaration of a variable only vbisible within the { } that encompasses it.
Place
int BCDnum;
outside the loop() function and lose the "int" where it is now inside the { }.
This a "variable scope" issue, a part of the C/C++ language to come to grips with one day soon.
Yikes! Sry sry sry, now I don't even see why it compiles, so obvsly I am thinking too little. The local declarations of all you I# variables should also be a problem.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2, INPUT); // BCD number coming in
pinMode(3, INPUT); // BCD number
pinMode(4, INPUT); // BCD number
pinMode(5, INPUT); // BCD number
pinMode(6, INPUT); // BCD number
pinMode(7, INPUT); // BCD number
pinMode(8, INPUT); // BCD number
pinMode(9, INPUT); // BCD number
pinMode(10, INPUT); // BCD number
pinMode(11, OUTPUT); // sets the digital pin 9 as output
}
void loop() {
int I0;
I0 = digitalRead(2);
int I1;
I1 = digitalRead(3);
int I2;
I2 = digitalRead(4);
int I3;
I3 = digitalRead(5);
int I4;
I4 = digitalRead(6);
int I5;
I5 = digitalRead(7);
int I6;
I6 = digitalRead(8);
int I7;
I7 = digitalRead(9);
int I8;
I8 = digitalRead(10);
int BCDnum = 0;
if (I0 == HIGH){
BCDnum = I1*1 + I2*2 + I3*4 + I4*8 + I5*10 + I6*20 + I7*40 + I8*80; //adding the BCD number up
}
if (I0 == HIGH && BCDnum > 0 && BCDnum < 100) {
Serial.print ("BCD Number: ");
Serial.println (BCDnum, DEC);
}
if (I0 == HIGH && BCDnum == 20){
digitalWrite(13,HIGH);
}
else {
digitalWrite(13,LOW);
}
// delay(1000);
// put your main code here, to run repeatedly:
}