need help in merging these 2 sketches.

first sketch:

#define RED 9
#define GREEN 10
#define BLUE 11
#define SIZE 255
#define DELAY 20
#define HUE_MAX 6.0
#define HUE_DELTA 0.01

//long deltas[3] = { 5, 6, 7 };
long rgb[3];
long rgbval;

float hue=0.0, saturation=1, value=1;

long bright[3] = { 107, 67, 256};
//long bright[3] = { 256, 256, 256};

long k, temp_value;

void setup () {
randomSeed(analogRead(4));
for (k=0; k<3; k++) {
pinMode(RED + k, OUTPUT);
rgb[k]=0;
analogWrite(RED + k, rgb[k] * bright[k]/256);
}
}

void loop() {
hue += HUE_DELTA;
if (hue > HUE_MAX) {
hue=0.0;
}
rgbval=HSV_to_RGB(hue, saturation, value);
rgb[0] = (rgbval & 0x00FF0000) >> 16;
rgb[1] = (rgbval & 0x0000FF00) >> 8;
rgb[2] = rgbval & 0x000000FF;
for (k=0; k<3; k++) {
analogWrite(RED + k, rgb[k] * bright[k]/256);
}

delay(DELAY);
}

long HSV_to_RGB( float h, float s, float v ) {

int i;
float m, n, f;

// not very elegant way of dealing with out of range: return black
if ((s<0.0) || (s>1.0) || (v<1.0) || (v>1.0)) {
return 0L;
}

if ((h < 0.0) || (h > 6.0)) {
return long( v * 255 ) + long( v * 255 ) * 256 + long( v * 255 ) * 65536;
}
i = floor(h);
f = h - i;
if ( !(i&1) ) {
f = 1 - f;
}
m = v * (1 - s);
n = v * (1 - s * f);
switch (i) {
case 6:
case 0:
return long(v * 255 ) * 65536 + long( n * 255 ) * 256 + long( m * 255);
case 1:
return long(n * 255 ) * 65536 + long( v * 255 ) * 256 + long( m * 255);
case 2:
return long(m * 255 ) * 65536 + long( v * 255 ) * 256 + long( n * 255);
case 3:
return long(m * 255 ) * 65536 + long( n * 255 ) * 256 + long( v * 255);
case 4:
return long(n * 255 ) * 65536 + long( m * 255 ) * 256 + long( v * 255);
case 5:
return long(v * 255 ) * 65536 + long( m * 255 ) * 256 + long( n * 255);
}
}

SECOND SKETCH:

#define BV{B01000100,B01000100,B01000100,B01000100,B01000100,B01000100,B00101000,B00010000}
#define BW{B10000010,B10000010,B10000010,B10000010,B10010010,B10010010,B10101010,B01101100}
#define BX{B10000010,B10000010,B01000100,B00101000,B00010000,B00101000,B01000100,B10000010}
#define BY{B10000010,B10000010,B01000100,B00101000,B00010000,B00010000,B00010000,B00010000}
#define BZ{B01111110,B00000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110}

#define LW{B00000000,B00000000,B00000000,B01000100,B01000100,B01010100,B01010100,B00111000}
#define LX{B00000000,B00000000,B00000000,B01000100,B00101000,B00010000,B00101000,B01000100}
#define LY{B00000000,B00000000,B00000000,B01000100,B01000100,B00111100,B00000100,B01111000}
#define LZ{B00000000,B00000000,B00000000,B01111100,B00000100,B00111000,B01000000,B01111100}

#define SPACE{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}
#define NUM0{B00111100,B01000010,B01000110,B01001010,B01010010,B01100010,B01000010,B00111100}
#define NUM1{B00011000,B00111000,B00011000,B00011000,B00011000,B00011000,B00011000,B00111100}
#define NUM2{B00111100,B01000010,B00000010,B00000010,B00001100,B00110000,B01000000,B01111110}
#define NUM3{B00111100,B01000010,B00000010,B00000010,B00011100,B00000010,B01000010,B00111100}
#define NUM4{B01000010,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00000010}
#define NUM5{B01111110,B01000000,B01000000,B01111100,B00000010,B00000010,B01000010,B00111100}
#define NUM6{B01111110,B01000000,B01000000,B01000000,B01111110,B01000010,B01000010,B01111110}
#define NUM7{B01111110,B00000010,B00000100,B00000100,B00001000,B00001000,B00010000,B00010000}
#define NUM8{B00111100,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B00111100}
#define NUM9{B01111110,B01000010,B01000010,B01111110,B00000010,B00000010,B01000010,B01111110}
#define DEVIDE{B00000100,B00000100,B00001000,B00001000,B00010000,B00010000,B00100000,B00100000}
#define TWODOTS{B00000000,B00011000,B00011000,B00000000,B00000000,B00011000,B00011000,B00000000}
#define DOT{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01100000,B01100000}
#define COMA{B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00110000,B01100000}
#define LINE{B00000000,B00000000,B00000000,B01111110,B01111110,B00000000,B00000000,B00000000}
#define QUASTION{B00111000,B01000100,B00000100,B00000100,B00001000,B00010000,B00000000,B00010000}
#define MARK{B00011000,B00011000,B00011000,B00011000,B00011000,B00000000,B00011000,B00011000}
/*
#define LESSTHAN
#define GRATTHAN
#define AT
#define POUND
#define DOLLAR
#define PERCENT
#define CARAT
#define AND
#define ASTERISK
#define LPARENTH
#define RPARENTH
#define HYPHEN
#define UNSCORE
#define PLUS
#define EQUALS
#define DASH
#define LBRACKET
#define RBRACKET
#define SYM[
#define SYM]
#define SYM|
#define SYM
#define SYM`
#define SYM~
#define SYM;
#define SYM:
*/

int latchPin = 10;
int clockPin = 13;
int dataPin = 11;
int clock = 9;
int Reset = 8;
int latchPinPORTB = latchPin - 8;
int clockPinPORTB = clockPin - 8;
int dataPinPORTB = dataPin - 8;
int i = 0;
long scrolling_word[16];
int array_turn=0;
byte your_text[60][8]={BH,BE,BL,BL,BO,SPACE,BW,BO,BR,BL,BD};//PUT YOUR TEXT HERE

void setup(){
Serial.begin(9600);
pinMode(dataPin,OUTPUT);
pinMode(clockPin,OUTPUT);
pinMode(latchPin,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(Reset,OUTPUT);
digitalWrite(Reset,HIGH);
digitalWrite(Reset,LOW);
setupSPI();
}

void display_word(int loops,byte word_print[8],int num_patterns,int delay_langth){
i = 0;
for(int g=0;g<8;g++)
scrolling_word[g] = 0;
for(int x=0;x<num_patterns;x++){

for(int r=0;r<8;r++)
scrolling_word[r] |= word_print[r];
for (int z=0;z<8;z++){
for(int p=0;p<8;p++)
scrolling_word[p] = scrolling_word[p] << 1;

for(int t=0;t<delay_langth;t++){
for(int y=0;y<8;y++){
if(i == 8){
digitalWrite(Reset,HIGH);
digitalWrite(Reset,LOW);
i = 0;
}
latchOff();
spi_transfer(make_word(0x01000000,y));
spi_transfer(make_word(0x00010000,y));
spi_transfer(make_word(0x00000100,y));
latchOn();
delayMicroseconds(800);
latchOff();
spi_transfer(0);
spi_transfer(0);
spi_transfer(0);
latchOn();
digitalWrite(clock,HIGH);
digitalWrite(clock,LOW);
i++;
}
}
}
}
finish_scroll(delay_langth);
}

void finish_scroll(int delay_scroll){
for (int n=0;n<24;n++){
for(int h=0;h<8;h++)
scrolling_word = scrolling_word << 1;
for(int w=0;w<delay_scroll;w++){
for(int k=0;k<8;k++){
if(i == 8){
digitalWrite(Reset,HIGH);
digitalWrite(Reset,LOW);
i = 0;
}
latchOff();
spi_transfer(make_word(0x01000000,k));
spi_transfer(make_word(0x00010000,k));
spi_transfer(make_word(0x00000100,k));
latchOn();
delayMicroseconds(800);
latchOff();
spi_transfer(0);
spi_transfer(0);
spi_transfer(0);
latchOn();
digitalWrite(clock,HIGH);
digitalWrite(clock,LOW);
i++;
}
}
}
}
byte make_word (long posistion,byte turn){
byte dummy_word = 0;
for(int q=0;q<8;q++){
if(scrolling_word[turn] & (posistion<<q))
dummy_word |= 0x01<<q;
}
return dummy_word;
}
void loop() {
display_word(1,your_text,20,15);
}
void latchOn(){
bitSet(PORTB,latchPinPORTB);
}
void latchOff(){
bitClear(PORTB,latchPinPORTB);
}
void setupSPI(){
byte clr;
SPCR |= ( (1<<SPE) | (1<<MSTR) );
//SPCR |= ( (1<<SPR1) | (1<<SPR0) );
SPCR &= ~( (1<<SPR1) | (1<<SPR0) );
clr=SPSR;
clr=SPDR;
SPSR |= (1<<SPI2X);
//SPSR &= ~(1<<SPI2X);
delay(10);
}
byte spi_transfer(byte data)
{
SPDR = data;
while (!(SPSR & (1<<SPIF)))
{
};
return SPDR;
}

Neither sketch is posted correctly. You have NOT defined any requirements for the resulting application, or even described what they do. So, don't expect help creating a program that does nothing. THAT is too easy.

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

This Simple Merge Demo may give you some ideas.

…R

Pin Conflict Alert.

First sketch:

#define RED       9
#define GREEN    10 
#define BLUE     11

Second sketch:

int latchPin = 10;
int clockPin = 13;
int dataPin = 11;
int clock = 9;
int Reset = 8;

I have found that there is only one reliable way to combine sketches. I think many newbies think code is a lot like HTML and they can cut and paste their way to a new sketch. The only way I have found is to understand fully what is happening in sketch 1 and then understand fully what is happening in sketch 2 then write a new sketch 3 combining what I learned. If you're lucky some functions may be able to be reused.

One strategy for merging two sketches is:

  1. resolve any pin conflicts (eg both sketches use pin 2 ) or global variable/function name conflicts (eg both scripts use the variable ‘i’ ) while the sketches are still separate. Attempt also to resolve other potential conflicts, say delay statements etc.
  2. Rename setup() and loop() from script 1 to setup1() and loop1() respectively.
  3. Rename setup() and loop() from script 2 to setup2() and loop2() respectively.
  4. combine all the code in a new script. The setup() in the new script simply calls setup1() and setup2(). The loop() in the new script simply calls loop1() and loop2().
  5. Debug / integrate the logic if required to get the separate bits to talk to each other / debug again etc.

It is not going to cover all cases, but it may get you started.

Do you know what these two sketches does? I assume no. You might have copied it from two different sources, as JimEli pointed, there are pin overlapping in those two codes. First understand what each sketch does.

Eliminate the digital pin overlapping.

There is no easy way in merging, you need to do line by line, if it's a function then can copy the whole function.

Merging is not hard if you know what you wanted.