Code works standalone, but not part of whole, help!

Hi,
I am trying to implement a battery monitoring circuit for my sensor module.
Here is the function I wrote for it:

int analogpin = A0;


void setup(){
for(int i= 33; i<53; i+=2)
{
  pinMode(i, OUTPUT);
}
Serial.begin(9600);
 }
 
void loop(){
  
 int analogvalue = map(analogRead(analogpin), 0, 1023, 1, 10);
  
  switch(analogvalue){
  case 1:
        digitalWrite(33, HIGH);
        digitalWrite(35, LOW);
        digitalWrite(37, LOW);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
  case 2:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, LOW);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;  
  case 3:        
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
  case 4:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
   case 5:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
   case 6:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;  
   case 7:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;   
    case 8:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;   
    case 9:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, HIGH);
        digitalWrite(51, LOW);
        break;   
    case 10:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, HIGH);
        digitalWrite(51, HIGH);
        break;
  }        
 
}

This works fine on an arduino with simply, just this code as the sketch. 7 LEDs light up(as they are supposed to in this case). However when I put this code into my entire sensor module code, random leds light up. the first five are stable and the next coulpe blink sometimes, clearly not working the way its supposed. Is this a current issue or is this a code issue?

THe entire sensor module code is a bit long, but here I go:

//----- Libraries -----//
#include <SPI.h>
#include <MPL115A1Lib.h>  // Pressure Sensor MPL115A1
#include <DHT.h>  // Temperature and Humidity Sensor RTH03
#include <U8glib.h>  // LCD Display 128x64
#include <floatToString.h>  // Converts floats to strings
#include <GPS610F.h>  // GPS-610F Module
#include <RFZuluArduino.h>  // Zulu 2km RF Module

//----- Defining Modules and Variables ------//
// Pressure Sensor
MPL115A1Lib PressSens;  // Defines Pressure Sensor for library
#define FT_TO_M(x) ((long)((x)*(0.3048)))
#define KPA_TO_INHG(x) ((x)*(0.295333727))
#define KPA_TO_MMHG(x) ((x)*(7.50061683))
#define KPA_TO_PSIA(x) ((x)*(0.145037738))
#define KPA_TO_KGCM2(x) ((x)*(0.0102))
#define INHG_TO_PSIA(x) ((x)*(0.49109778))
#define DEGC_TO_DEGF(x) ((x)*(9.0/5.0)+32.0)
float press_pKa = 0;
float temp_c= 0;
long alt_ft = 0;
char charPress[7];  // Stores pressure
char charTemp[6];  // Stores temperature in C
char charAlt[5];  // Stores altitude

// Temperature & Humidity Sensor
#define DHTPIN 48     // Defines signal pin connection
#define DHTTYPE DHT22   // Defines Sensor model # DHT22 (RTH03)
DHT dht(DHTPIN, DHTTYPE);  // Defines the Temp/Humd Sensor
float t = 0;  // temp
float h = 0;  // rel. humd.
float f = 0;  // temp in f
float hi = 0;  // heat index
char rh[6];  // Stores Relative Humidity
char tempC[6];  // Stores Temperature in °C
char tempF[7];  // Stores Temp in F
char heatIndex[7];  // Stores heat index
char degree[3] = {176, 67};  // Stores °C symbol
char degreeF[3] = {176, 70};  // Stores °F symbol

// LCD Display
U8GLIB_ST7920_128X64_4X u8g(41, 42, 43);  // Defines LCD pins (SPI: EN = 41, RW = 42, RS = 43)

// GPS Module
GPS610F gps(17, 16, 28, 26, 44, 27, 9600);  // Defines GPS pins (SDI, SDO1, SDO2, PIO, PPS, RST, baudRate)
String gpsData;
char charGPS[82] = "";
char nmeaProto[6] = "";
char utcTime[11] = "";
char gpsStatus[2] = "";
char latitude[11] = "";
char nsIndicator[2] = "";
char longitude[11] = "";
char ewIndicator[2] = "";
char speedOverGnd[6] = "";
char courseOverGnd[6] = "";
char utcDate[7] = "";
char magVarDegrees[6] = "";
char magVarDirection[2] = "";
char modeIndicator[2] = "";
char checkSum[3] = "";
char tempTime[9] = "";
char tempDate[9] = "";
char tempLat[12] = "";
char tempLong[13] = "";

// RF Module
RFZuluArduino rf(15, 14, 2, 3, 4, 5, 4800);  // Defines the RF module's pins (rx1, tx1, RTS, CTS, RST, PD, baudRate)

//Geiger Counter
unsigned int gcount = 0;
unsigned int countStartTime = 0;
int countsPerMinute=0;

//Battery Monitor
int analogpin = A0;
int analogvalue;
int misc=0;

String str;  // temporary string
int draw_state = 0;
int tracker = 0;
void setup() {
  Serial1.begin(9600); 
  //Serial.begin(9600); 
  dht.begin();
  
  //LCD startup
  LCDprepare();
  AECLlogo();
  
  //Battery Monitor
  for(int i= 33; i<53; i+=2)
{
  pinMode(i, OUTPUT);
}
}
void loop() {
  
  delay(1000);
  //Initiates Battery Monitor
  Monitor();

  //----- Get Sensor Data -----//
  // Temp/Humid
  h = dht.readHumidity();
  t = dht.readTemperature();
  f = dht.readTemperature(true); 
  hi = dht.computeHeatIndex(f, h);

  // Pressure Sensor 
  press_pKa = PressSens.calculatePressurekPa();
  alt_ft = PressSens.calculateAltitudeFt(press_pKa);

  //Geiger Counter
  while (Serial1.available() > 0) {  // Check if geiger counter is available
     int inChar = Serial1.read();  // read char from geiger counter
     if (inChar == '0' || inChar == '1') {  // 0 and 1 represent an event
       gcount++;  // increase count
      }
  }
  unsigned int now = millis();  // now is the time in milliseconds since start of program
  unsigned int elapsedTime = now - countStartTime;  // time elapsed
  if (elapsedTime >= 60000) {
    countsPerMinute = gcount;    
    // reset timers
    gcount = 0;
    countStartTime = now;
  }


  //----- Convert to Transmit -----//
  // Temp/Humid
  floatToString(rh, h, 1);  // relative humidity
  floatToString(tempC, t, 1);  // temperature in C
  floatToString(tempF, f, 1);  // temp in F
  floatToString(heatIndex, hi, 1);  // heat index

  // Pressure Sensor
  str = String(FT_TO_M(alt_ft));  // convert altitude in ft to m
  str.toCharArray(charAlt, 5);  // covert string to char array
  floatToString(charPress, press_pKa, 2);
  
  // GPS Module*****************************************************
  gps.getData().toCharArray(charGPS, 80);
  gps.dataFields(0).toCharArray(nmeaProto, 6);
  // time
  gps.dataFields(1).toCharArray(utcTime, 11);
  tempTime[0] = utcTime[0];
  tempTime[1] = utcTime[1];
  tempTime[2] = ':';
  tempTime[3] = utcTime[2];
  tempTime[4] = utcTime[3];
  tempTime[5] = ':';
  tempTime[6] = utcTime[4];
  tempTime[7] = utcTime[5];
  gps.dataFields(2).toCharArray(gpsStatus, 2);
  // latitude
  gps.dataFields(3).toCharArray(latitude, 11);
  gps.dataFields(4).toCharArray(nsIndicator, 2);
  tempLat[0] = latitude[0];
  tempLat[1] = latitude[1];
  tempLat[2] = 176;   // °
  tempLat[3] = latitude[2];
  tempLat[4] = latitude[3];
  tempLat[5] = latitude[4];
  tempLat[6] = latitude[5];
  tempLat[7] = latitude[6];
  tempLat[8] = 39;  // '
  tempLat[9] = ' ';
  tempLat[10] = nsIndicator[0];
  // longitude
  gps.dataFields(5).toCharArray(longitude, 11);
  gps.dataFields(6).toCharArray(ewIndicator, 2);
  tempLong[0] = longitude[0];
  tempLong[1] = longitude[1];
  tempLong[2] = longitude[2];
  tempLong[3] = 176;   // °
  tempLong[4] = longitude[3];
  tempLong[5] = longitude[4];
  tempLong[6] = longitude[5];
  tempLong[7] = longitude[6];
  tempLong[8] = longitude[7];
  tempLong[9] = 39;  // '
  tempLong[10] = ' ';
  tempLong[11] = ewIndicator[0];
  gps.dataFields(7).toCharArray(speedOverGnd, 6);
  gps.dataFields(8).toCharArray(courseOverGnd, 6);
  // date
  gps.dataFields(9).toCharArray(utcDate, 7);
  tempDate[0] = utcDate[0];
  tempDate[1] = utcDate[1];
  tempDate[2] = '/';
  tempDate[3] = utcDate[2];
  tempDate[4] = utcDate[3];
  tempDate[5] = '/';
  tempDate[6] = utcDate[4];
  tempDate[7] = utcDate[5];
  gps.dataFields(10).toCharArray(magVarDegrees, 6);
  gps.dataFields(11).toCharArray(magVarDirection, 2);
  gps.dataFields(12).toCharArray(modeIndicator, 2);
  gps.dataFields(13).toCharArray(checkSum, 3);
  
  //GeigerCounter Conversions
  
  String geigerbuffer = String(countsPerMinute);
  char gbuff[5];
  geigerbuffer.toCharArray(gbuff,5);
  
  // transmit the data
  rf.transmit(charGPS, tempC, rh, charPress, gbuff);
  
  /*test
  
  Serial.println(charGPS);
   Serial.println(tempC);
    Serial.println(rh);
     Serial.println(charPress);
      Serial.println(gbuff);
  */
  
  //----- Output to LCD Display -----//
  u8g.firstPage();  
  do {
    draw();
  } 
  while( u8g.nextPage() );

  tracker++;
  if (tracker <= 2){
    draw_state = 0;
  } 
  else if (tracker <= 5){
    draw_state = 1;
  } 
  /*else if (tracker <= 8){
    draw_state = 2;
  } */
  else {
    tracker = 0;
  }
}
void draw(void) {
  LCDprepare();
  switch (draw_state){
  case 0: 
    //AECLlogo(); 
    SensorInfo(); 
    break;
  case 1: 
    //SensorInfo(); 
    GpsInfo(); 
    break;
  /*case 2: 
    GpsInfo(); 
    break;
  */
  }
}
void SensorInfo(){
  // Banner
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_ncenR08);
  u8g.drawStr(12,8, "Sensor Readings:");
  battery();  // show charge
  // Sensor Readings
  tempHumd();
  pressSens();
}

void GpsInfo(){
  // Banner
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_ncenR08);
  u8g.drawStr(15,8, "GPS Information");
  battery();  // show charge
  GPSOutput();
}
void battery(){
  // body of the battery
  u8g.drawFrame(112,0,16,7);
  u8g.drawFrame(111,2,1,3);
  u8g.drawBox(113,1,14,5);  // fills in the battery
  u8g.setColorIndex(0);
  u8g.setFont(u8g_font_p01type);
  u8g.drawStr(113, 5, "100");
  u8g.drawStr(123, 5, "%");
}
void tempHumd(){
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  //Temperature
  u8g.drawStr(0, 20, "Temperature:");
  u8g.drawStr(61, 20, tempC);
  u8g.drawStr(81, 20, degree);  // °C
  u8g.drawStr(91, 20, "/");
  u8g.drawStr(98, 20, tempF);
  u8g.drawStr(118, 20, degreeF);  // °F
  //%RH
  u8g.drawStr(13, 30, "Humidity:");
  u8g.drawStr(74, 30, rh);
  u8g.drawStr(95, 30, "%RH");
  //Heat index
  u8g.drawStr(8, 40, "Heat Index:");
  u8g.drawStr(75, 40, heatIndex);
  u8g.drawStr(97, 40, degreeF);  // °F
}
void pressSens(){
  u8g.drawStr(10, 50, "Pressure:");
  u8g.drawStr(72, 50, charPress);
  u8g.drawStr(97, 50, "kPa");

  u8g.drawStr(14, 60, "Altitude:");
  u8g.drawStr(77, 60, charAlt);
  u8g.drawStr(98, 60, "m"); 
}
void GPSOutput(){
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(1, 20, "Date:");
  u8g.drawStr(26, 20, tempDate);  // UTC date
  u8g.drawStr(69, 20,  "Time:");
  u8g.drawStr(93, 20, tempTime);  // UTC time
  u8g.drawStr(11, 30, "Status:");
  u8g.drawStr(48, 30, gpsStatus);  // Gps status
  u8g.drawStr(73, 30, "Mode:");
  u8g.drawStr(105, 30, modeIndicator);  // mode indicator
  u8g.drawStr(20, 40, "Latitude:");
  u8g.drawStr(65, 40, tempLat);  // Latitude
  u8g.drawStr(15, 50, "Longitude:");
  u8g.drawStr(65, 50, tempLong);  // Longitude
  u8g.drawStr(1, 60, "Speed:");
  u8g.drawStr(31, 60, speedOverGnd);  // Speed over ground
  u8g.drawStr(52, 60, "km");
  u8g.drawStr(68, 60,  "Course:");
  u8g.drawStr(102, 60, courseOverGnd);  // course over ground
  u8g.drawStr(124, 60, degree);  // °
}
void LCDprepare(){
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_6x10);
  u8g.setFontRefHeightExtendedText();
  u8g.setDefaultForegroundColor();
  u8g.setFontPosTop();
}
void AECLlogo(){
  u8g.setColorIndex(1);  // Sets pixels on
  // top to bottom left
  u8g.drawLine(64, 0, 35, 64);
  u8g.drawLine(64, 0, 36, 64);
  u8g.drawLine(64, 0, 37, 64);
  u8g.drawLine(64, 0, 38, 64);
  u8g.drawLine(64, 0, 39, 64);
  u8g.drawLine(64, 0, 40, 64);
  u8g.drawLine(64, 0, 41, 64);
  u8g.drawLine(64, 0, 42, 64);
  // top to bottom right
  u8g.drawLine(64, 0, 93, 64);
  u8g.drawLine(64, 0, 92, 64);
  u8g.drawLine(64, 0, 91, 64);
  u8g.drawLine(64, 0, 90, 64);
  u8g.drawLine(64, 0, 89, 64);
  u8g.drawLine(64, 0, 88, 64);
  u8g.drawLine(64, 0, 87, 64);
  u8g.drawLine(64, 0, 86, 64);
  // bottom right to middle left
  u8g.drawLine(38, 32, 92, 64);
  u8g.drawLine(38, 32, 91, 64);
  u8g.drawLine(37, 32, 90, 64);
  u8g.drawLine(37, 32, 89, 64);
  u8g.drawLine(36, 32, 88, 64);
  u8g.drawLine(36, 32, 87, 64);
  // left to right
  u8g.drawLine(36, 32, 92, 31);
  u8g.drawLine(36, 32, 92, 32);
  u8g.drawLine(36, 32, 92, 32);
  u8g.drawLine(36, 32, 92, 33);
  u8g.drawLine(36, 32, 92, 34);
  u8g.drawLine(36, 32, 92, 35);
  u8g.drawLine(36, 33, 92, 36);
  u8g.drawLine(36, 33, 92, 37);
  u8g.setColorIndex(0);  // sets pixels off
  u8g.drawDisc(92,34,3, U8G_DRAW_ALL);  // draws filled circle
  u8g.setColorIndex(1);  // sets pixels on
  u8g.drawDisc(96,34,4, U8G_DRAW_ALL);  // draws filled circle
  // top line
  u8g.drawLine(96,27,92,23);
  u8g.drawLine(95,27,91,23);
  u8g.drawLine(97,27,93,23);
  // bottom line
  u8g.drawLine(96,41,92,45);
  u8g.drawLine(95,41,91,45);
  u8g.drawLine(97,41,93,45);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(102, 52,  "AECL");
  u8g.drawStr(102, 60,  "EACL");

}

int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

void Monitor(){
 
int analogvalue = map(analogRead(analogpin), 0, 1023, 1, 10);
  switch(analogvalue){
  case 1:
        digitalWrite(33, HIGH);
        digitalWrite(35, LOW);
        digitalWrite(37, LOW);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
  case 2:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, LOW);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;  
  case 3:        
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
  case 4:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
   case 5:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
   case 6:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;  
   case 7:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;   
    case 8:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;   
    case 9:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, HIGH);
        digitalWrite(51, LOW);
        break;   
    case 10:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, HIGH);
        digitalWrite(51, HIGH);
        break;
  }        
 
}

It is definitely NOT an arduino issue. Previously , I was using a different arduino with the battery function alone. I tested the function alone with the arduino with all the sensors attached and it worked. So it might be a code issue, current issue(?). I have no idea.

Any help would be appreciated a whole effin lot

Do you know if the analogValue is correct?
Can you insert a Serial.println() to observe it?

While it is unlikely to be relevant to your problem, have you not heard of arrays and FOR loops to make your code shorter and simpler?

...R

aha, yes I have heard of array and for loops(both are used in the code) and I actually did that battery function is a nice little loop but it didn't work, so just for the sake of trying, I changed the format into switch/case.

Also, I'll give the serial print a try and post what I get.
Thanks!

Lots of code, not much in the way of debug prints.

if you declare the 10 led pins into an array like this:

const int ledPin[10] = {33,35,37,39,41,43,45,47,49,51};

you can reduce this entire block of code:

int analogvalue = map(analogRead(analogpin), 0, 1023, 1, 10);
  
  switch(analogvalue){
  case 1:
        digitalWrite(33, HIGH);
        digitalWrite(35, LOW);
        digitalWrite(37, LOW);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
  case 2:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, LOW);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;  
  case 3:        
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, LOW);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
  case 4:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, LOW);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
   case 5:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, LOW);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;
   case 6:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, LOW);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;  
   case 7:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, LOW);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;   
    case 8:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, LOW);
        digitalWrite(51, LOW);
        break;   
    case 9:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, HIGH);
        digitalWrite(51, LOW);
        break;   
    case 10:
        digitalWrite(33, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(43, HIGH);
        digitalWrite(45, HIGH);
        digitalWrite(47, HIGH);
        digitalWrite(49, HIGH);
        digitalWrite(51, HIGH);
        break;
  }

down to this:

int analogvalue = map(analogRead(analogpin), 0, 1023, 1, 10);
for (int i = 0; i < 10; i++)
{
  digitalWrite(ledPin[i],(i<= analogvalue? HIGH ; LOW));
}

I get a constant stream of value:

886
888
885
886
888
885
889
889
888
889
891
886
892
893
890
888
885
889
890

Thanks bullldog! makes reading it a lot easier.

Your stream of readings seems to be consistent so I don't immediately see why the LEDs might be flashing.

Is there any risk that the value is hovering between two of the mapped points?

Because of the long-handed way that you have written the code coupled with the long-handed way that the new Forum displays code I find it impossible to get an overview of your project which might enable me to see another sort of problem.

If you re-write the code with arrays and post the new shorter version it may be easier to see the problem.

Another thought is that it may be sufficient to update the LEDs 2 or 3 times per second (using millis() to manage the timing).

...R

Just a small point that may (or may not) be anything to do with your problem. You are using .toCharArray When calling this function you have to pass the size of the buffer.

Ideally the buffer should be 1 byte bigger than the value you pass (to allow for the 0 terminator) I notice you are passing EXACTLY the size of the char array.

For example

char longitude[11] = "";
...
...
...
 gps.dataFields(5).toCharArray(longitude, 11);

I'd suggest this should EITHER be

char longitude[12] = "";
...
...
...
 gps.dataFields(5).toCharArray(longitude, 11);

OR

char longitude[11] = "";
...
...
...
 gps.dataFields(5).toCharArray(longitude, 10);

OH crap! I just realized something. So stupid of me.
I looked at my wiring chart and pins 51,49, and 43 are in use by my pressure sensor.Although this doesnt explain why the other led`s are not working, Ill change up some led pins and give it a shot again

Problem solved. It was indeed a wiring issue. Thanks for helping make my code shorter and easier to ready guys!