Code Monkey home page Code Monkey logo

autosteerpcbv2lb's Introduction

Hi there ๐Ÿ‘‹

My GitHub stats

Top Langs

autosteerpcbv2lb's People

Contributors

mattwoodhead avatar mnltake avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bigrobbuckley

autosteerpcbv2lb's Issues

Bare Bones

Hi there,

Thank you for all the great work you have done on this. Works great on an Uno. To shrinkify I was hoping to put on a sparkfun pro micro, ATmega32U4. The code as is doesn't run due to the PWM definitions I think. TCCR1B etc. I don't need to run any of the sensor or relay etc stuff, I'm literally just using it for the lightbar. What is the minimum code required for it to run? I can't seem to make it run.
I have tried:

#define Neopixel_Pin 16                 // Set this to the pin number you are using for the Neopixel strip controll line
#define Neopixel_Brightness 120        // brightness value between 0 and 255
#define mmPerLightbarPixel  20         // 40 = 4cm

//Neopixels
  #include <Adafruit_NeoPixel.h>
  Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, Neopixel_Pin, NEO_GRBW + NEO_KHZ800);
  const byte centerpixel = (NUMPIXELS-1)/2;
  byte levelcolor[NUMPIXELS][3];

//Parsing PGN
  bool isPGNFound = false, isHeaderFound = false;
  uint8_t pgn = 0, dataLength = 0, idx = 0;
  int16_t tempHeader = 0;

//show life in AgIO
  uint8_t helloAgIO[] = {0x80,0x81, 0x7f, 0xC7, 1, 0, 0x47 };
  uint8_t helloCounter=0;

  int16_t distanceFromLine = 32020;  // cross track error - Lightbar PGN (249) bytes 5 * 6. Start at 32020 so it is ignored untill a value is received from AOG
  int16_t prevDistFromLine = 0;  // Used to only send the lightbar data if the distance has changed

void setup() {
  
//set up communication
  Serial.begin(38400);

//start neopixels
  pixels.begin();
   for (int i =0 ;i < centerpixel;i++){ //Right
     levelcolor[i][0]=0; levelcolor[i][1]=Neopixel_Brightness; levelcolor[i][2]=0; // Green (Right)
   }
   for (int i = centerpixel+1;i < NUMPIXELS;i++){ //Left
     levelcolor[i][0]=Neopixel_Brightness; levelcolor[i][1]=0; levelcolor[i][2]=0; // Red (Left)
   }
   levelcolor[centerpixel][0]=20; levelcolor[centerpixel][1]=20;levelcolor[centerpixel][2]=0;  // Yellow (centerpixel)

}

void loop() {
  
// Serial Receive
    //Do we have a match with 0x8081?    
    if (Serial.available() > 1 && !isHeaderFound && !isPGNFound) 
    {
      uint8_t temp = Serial.read();
      if (tempHeader == 0x80 && temp == 0x81) 
      {
        isHeaderFound = true;
        tempHeader = 0;        
      }
      else  
      {
        tempHeader = temp;     //save for next time
        return;    
      }
    }
  
    //Find Source, PGN, and Length
    if (Serial.available() > 2 && isHeaderFound && !isPGNFound)
    {
      Serial.read(); //The 7F or less
      pgn = Serial.read();
      dataLength = Serial.read();
      isPGNFound = true;
      idx=0;
    } 

    //The data package
    if (Serial.available() > dataLength && isHeaderFound && isPGNFound)
    {
  
  if (pgn==249) //FC Light bar PGN
      {         
        //cross track error byte 5 & 6
        distanceFromLine = ((int16_t)(Serial.read() << 8 | Serial.read()));

        //crc byte 7
        Serial.read();

        //reset for next pgn sentence
        isHeaderFound = isPGNFound = false;
        pgn=dataLength=0;
      }

      //clean up strange pgns
      else
      {
          //reset for next pgn sentence
          isHeaderFound = isPGNFound = false;
          pgn=dataLength=0; 
      }
      } //end if (Serial.available() > dataLength && isHeaderFound && isPGNFound)  

if (distanceFromLine != prevDistFromLine)  // only update the lightbar if it has changed
      {
        lightbar(distanceFromLine);
        prevDistFromLine = distanceFromLine;  // set the previous XTE value to the one we have just used for next time
      }
}

void lightbar(int16_t distanceFromLine ){
    int16_t display_dist = constrain (distanceFromLine / mmPerLightbarPixel , -centerpixel ,centerpixel);
    byte n = display_dist + centerpixel;
      for (int i = 0 ;i < NUMPIXELS; i++){
        if ( (i == centerpixel && i == n)|| //Center
             (display_dist < 0 && i >= n && i <= centerpixel && distanceFromLine != 32020 && distanceFromLine != 32000)|| //Right Bar
             (display_dist > 0 && i <= n && i > centerpixel && distanceFromLine != 32020 && distanceFromLine != 32000) ) //Left Bar
        {
          pixels.setPixelColor(i,levelcolor[i][0],levelcolor[i][1],levelcolor[i][2]);
        }else{
          if (i == centerpixel){
            pixels.setPixelColor(i,10,10,0); // Dimmer yellow (we arent on centre)
          } else {
            pixels.setPixelColor(i,0,0,0); //Clear
          }
        }
      }
    pixels.show();
    delayMicroseconds(50);  // tiny delay after sending the colours to allow the colours to latch in the LEDs
  }

Any help would be greatly appreciated,

Many thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.