2 different sketch work - the combined one doesn't

hallo again

i am trying to conect a real car cluster with pc racing games
and here what i have made so far

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1280139142

so now i am working on a BMW cluster

that has 3 Pwm meters and one Aircore meter

a simple pwm is ok for each of the three meters

and for the rpm meter you need to controll 2 coils

so we need two digital i/o pins for each coil because we need to change the polarity and one pwm pin because we want to change the “votage” on the coil

so finaly we need

4 i/o pins
2 pwm pins
and one h-bridge (l293D)

now the hardware is ready and two different sketchs are ready and full working

this is for the aircores that is a copy of that
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1271537811/7#7

void setup()
{
//Set the pins to OUTPUT
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);

}

void loop() // run over and over again
{

for(float i = 0; i < 255; i++){
setAircore(i);
delayMicroseconds(10000); // waits for delayTime milliseconds
}

for(float i = 255; i > 0; i–){
setAircore(i);
delayMicroseconds(10000); // waits for delayTime milliseconds
}
}

void setAircore(float pos){
pos = pos/40.58;

float sinCoilValue = 255sin(pos);
float cosCoilValue = 255
cos(pos);

if (sinCoilValue<=0) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
}
else {
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
}
if (cosCoilValue<=0) {
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
}
else {
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
}

sinCoilValue = abs(sinCoilValue);
cosCoilValue = abs(cosCoilValue);

analogWrite(6, sinCoilValue);
analogWrite(5, cosCoilValue);
}

and here is the second one for the 3 meters

int rpm;
int Speed;
int fuel;
int turbo;
char kind_of_data;

void setup(){

Serial.begin(115200);

pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

calibration();
}

void loop()
{
//****************************** READ DATA FROM SERIAL ******************************
while(Serial.available() > 0)
{

kind_of_data = Serial.read();
//if (kind_of_data == ‘R’ ) Read_Rpm();
if (kind_of_data == ‘S’ ) Read_Speed();
if (kind_of_data == ‘F’ ) Read_Fuel();
if (kind_of_data == ‘T’ ) Read_Turbo();
//if (kind_of_data == ‘E’ ) Read_EBrake();
//if (kind_of_data == ‘B’ ) Read_Brake();

}
//****************************** READ DATA FROM SERIAL END ******************************
}

void Read_Rpm(){

delay(1);
int Rpm100 = Serial.read()- ‘0’;
delay(1);
int Rpm10 = Serial.read()- ‘0’;
delay(1);
int Rpm1 = Serial.read()- ‘0’;

int rpm = 100Rpm100 + 10Rpm10 + Rpm1;
}

void Read_Speed(){

delay(1);
int Speed100 = Serial.read()- ‘0’;
delay(1);
int Speed10 = Serial.read()- ‘0’;
delay(1);
int Speed1 = Serial.read()- ‘0’;

Speed = 100Speed100 + 10Speed10 + Speed1;
analogWrite(9,map(Speed,127,255,17,155));
}

void Read_Fuel(){
delay(1);
int Fuel100 = Serial.read()- ‘0’;
delay(1);
int Fuel10 = Serial.read()- ‘0’;
delay(1);
int Fuel1 = Serial.read()- ‘0’;

fuel = 100Fuel100 + 10Fuel10 + Fuel1;
analogWrite(10,map(fuel,127,255,110,255));
}

void Read_Turbo(){
delay(1);
int Turbo100 = Serial.read()- ‘0’;
delay(1);
int Turbo10 = Serial.read()- ‘0’;
delay(1);
int Turbo1 = Serial.read()- ‘0’;

turbo = 100Turbo100 + 10Turbo10 + Turbo1;
analogWrite(11,map(turbo,127,255,30,255));
}

void setAircore(float pos){
pos = pos/40.58;

float sinCoilValue = 255sin(pos);
float cosCoilValue = 255
cos(pos);

if (sinCoilValue<=0) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
}
else {
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
}
if (cosCoilValue<=0) {
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
}
else {
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
}

sinCoilValue = abs(sinCoilValue);
cosCoilValue = abs(cosCoilValue);

analogWrite(6, sinCoilValue);
analogWrite(5, cosCoilValue);
}

void Leds(int leds){

digitalWrite(12, LOW);
if ( leds == 0 ) shiftOut(7, 13, MSBFIRST, B00000000);
if ( leds == 1 ) shiftOut(7, 13, MSBFIRST, B00000001);
if ( leds == 2 ) shiftOut(7, 13, MSBFIRST, B00000011);
if ( leds == 3 ) shiftOut(7, 13, MSBFIRST, B00000111);
if ( leds == 4 ) shiftOut(7, 13, MSBFIRST, B00001111);
if ( leds == 5 ) shiftOut(7, 13, MSBFIRST, B00011111);
if ( leds == 6 ) shiftOut(7, 13, MSBFIRST, B00111111);
if ( leds == 7 ) shiftOut(7, 13, MSBFIRST, B01111111);
if ( leds == 8 ) shiftOut(7, 13, MSBFIRST, B11111111);
digitalWrite(12, HIGH);
}

void calibration(){

for( int calib=0; calib<256; calib++ ){
analogWrite(9,map(calib,0,255,17,165));
analogWrite(10,map(calib,0,255,110,255));
analogWrite(11,map(calib,0,255,30,255));
Leds(map(calib,0,255,0,8));

delay(15);
}

for( int calib=255; calib>=0; calib-- ){
analogWrite(9,map(calib,0,255,17,165));
analogWrite(10,map(calib,0,255,110,255));
analogWrite(11,map(calib,0,255,30,255));
Leds(map(calib,0,255,0,8));

delay(15);
}

analogWrite(9,0);
analogWrite(10,0);
analogWrite(11,0);
}

but my problem is that when

i upload that

void calibration(){

for( int calib=0; calib<256; calib++ ){
analogWrite(9,map(calib,0,255,17,165));
analogWrite(10,map(calib,0,255,110,255));
analogWrite(11,map(calib,0,255,30,255));
Leds(map(calib,0,255,0,8));

delay(15);
}

for( int calib=255; calib>=0; calib-- ){
analogWrite(9,map(calib,0,255,17,165));
analogWrite(10,map(calib,0,255,110,255));
analogWrite(11,map(calib,0,255,30,255));
Leds(map(calib,0,255,0,8));

delay(15);
}

analogWrite(9,0);
analogWrite(10,0);
analogWrite(11,0);

for(float i = 0; i < 255; i++){
setAircore(i);
delayMicroseconds(10000); // waits for delayTime milliseconds
}

for(float i = 255; i > 0; i–){
setAircore(i);
delayMicroseconds(10000); // waits for delayTime milliseconds
}
}

only the 3 meters work and not the aircore

why???

and here is a video

thanks a lot

I'm a little confused by all of the posts. Did any of these posts contain the full sketch that does not work?

I ITHINK it is sketch #2, with the calibration routine substituted from sketch #3...

yes exactly

when i am runing calibration without the

for(float i = 0; i < 255; i++){
setAircore(i);
delayMicroseconds(10000); // waits for delayTime milliseconds
}

for(float i = 255; i > 0; i–){
setAircore(i);
delayMicroseconds(10000); // waits for delayTime milliseconds
}

it works fine and the 3 meters work fine

if i add the aircore code the 3 meters works fine but the aircore no

but if i upload a sketch with only the aircore code it works

I just see that you use digital lines 0 and 1 AND Serial. This will clash hard. with undefined results...

yes thanks a lot

that should be

i will test it tomorow

thankssssssssssssssss