How do I combine 2 codes together?

Hi,

the first code is this

int Heart = A0;
int value = 0;
int Motor = 12;
int Thresh = 560;
int ReadRate = 25;
int UnderCount = 0;
int OverCount = 0;
String OutValue = “”;

void setup() {
// put your setup code here, to run once:
Serial.begin(19200);
pinMode(Motor, OUTPUT);
delay(2500);
}

void loop() {
// put your main code here, to run repeatedly:
value = analogRead(Heart);
if (value > Thresh ){
digitalWrite(Motor, HIGH); // When the heart senor hits the thresh it vibrates
delay(10); // delay to read the BMP
digitalWrite(Motor, LOW); // under the thresh it would vibrates softly
Serial.println(value);

}
}

Second code is this one

#include <U8glib.h>

#include “U8glib.h”
U8GLIB_SSD1351_128X128_332 u8g(13, 11, 8, 9, 7); // Arduino UNO: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, DC = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)

void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
//int value = 0;
//char buf[9];
//sprintf (buf, “%d”, value);
//u8g.drawStr( 0, 40, buf);
String value = “test”;
value = read();
u8g.setPrintPos( 0, 40);
u8g.print(value);
}

void setup(void) {

// flip screen, if required
// u8g.setRot180();

// set SPI backup if required
//u8g.setHardwareBackup(u8g_backup_avr_spi);

// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
}

void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );

// rebuild the picture after some delay
delay(500);

}

I’ve tried to put together the codes but there is always an error. I don’t really understand as I am new to coding in general and still learning the context of it all. If you can help the would be great, if not, cool.

Thank you!!

Show the attempt to combine your codes. Please use code tags when posting.

Please give us the error messages; you can click in the output window and select all orange text and copy and paste it here.

Generic sketch combining procedure:

Combine the contents of loop() into one loop() function

Combine the contents of setup() into one setup() function

Put all the stuff that's not inside loop or setup, from both sketches, into the combined sketch, outside loop() and setup()

Then try to compile and see what it complains about and fix it.

Hi,
Some suggestions on combining sketches on THIS Page