Sunday, July 30, 2017

Matrix Display 8 x 8

Matrix Display 8 x 8.


Allows user to create patterns on an 8x8 display by setting bits in an array. A square figure and a face are displayed in the code. You can create your own patterns by changing the bits in the arrays shown.





NOTE: Include the library ledcontrol by searching for ledcontrol in the library manager

Copy Code Below -----------------

#include <LedControl.h>

int DIN = 12;
int CLK =  11;
int CS = 10;

LedControl lc=LedControl(DIN,CLK,CS,0);

void setup(){
 lc.shutdown(0,false);     //The MAX72XX is in power-saving mode on startup
 lc.setIntensity(0,15);     // Set the brightness to maximum value
 lc.clearDisplay(0);         // and clear the display
}

void loop(){ 

//Create an array of 8 bytes (64 bits) containing a patterns of 1's (lit) and 0's (not lit)

//This patterns of ones will create a square as outlined by the 1's in the 2 dimensional array below://
byte square[8]= {B11111111,
          B10000001,
          B10000001,
          B10000001,
          B10000001,
          B10000001,
          B10000001,
          B11111111};

//This patterns of ones will create a smiley face as outlined by the 1's in the 2 dimensional array below://
byte face[8]=   {B00000000, 
           B00000000,
           B01000010,
           B00000000,
           B00010000,
           B01000010,
           B00111100,
           B00000000};

    printByte(square);
    delay(1000);
    printByte(face);
    delay(1000);
}

// The code below is a function. This function takes data from an particular shape array and sends it to the display

void printByte(byte character [])
{
  int i = 0;
      for(i=0;i<8;i++)
    {
        lc.setRow(0,i,character[i]);
    }
}

Copy Code Above -----------------

Going Further::

1) Create different patterns by creating the required array
2) Change program to cycle through several patterns with a delay between patterns
3) Create an animation by cycling through several patterns like a smiley face
4) Create digit patterns from 1 to 9 

Saturday, July 1, 2017

Motion Processor

Motion Processor

This is a complex device using I2C communication, which almost always frustrates beginners. If you want to use an accellerometer I recommend using the ADXL-335 analog sensor since it is much easier to interface with and does not require a library. The accuracy is lower for the ADXL-335 but lower level of frustration is well worth it.



Code for Motion Processor
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69

MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

#define OUTPUT_READABLE_ACCELGYRO

void setup() {
    Wire.begin();

    Serial.begin(38400);

    accelgyro.initialize();

    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
}

void loop()
{
    accelgyro.getAcceleration(&ax, &ay, &az);

        Serial.print("a/g:\t");
        Serial.print((ax/256)+128); Serial.print("\t"); //Dividing decreases accuracy we should truncate MSBs
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);
}