Monday 28 January 2019

My project on programmable Digital Instruments

code for the project



click for report and apps aia files


https://drive.google.com/open?id=1np-_N0H5cl_in80sghVV8tPg8xlTZRKg






///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////senthamizhanjackie@gmail.com////////////////////////////////


#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

#define DAC_RESOLUTION    (8)

///////////////triangle wave lookup///////////////////

const PROGMEM uint16_t Lookup_tri[256] =
{
  32, 64, 96, 128, 160, 192, 224, 256,
  288, 320, 352, 384, 416, 448, 480, 512,
  544, 576, 608, 640, 672, 704, 736, 768,
  800, 832, 864, 896, 928, 960, 992, 1024,
  1056, 1088, 1120, 1152, 1184, 1216, 1248, 1280,
  1312, 1344, 1376, 1408, 1440, 1472, 1504, 1536,
  1568, 1600, 1632, 1664, 1696, 1728, 1760, 1792,
  1824, 1856, 1888, 1920, 1952, 1984, 2016, 2048,
  2079, 2111, 2143, 2175, 2207, 2239, 2271, 2303,
  2335, 2367, 2399, 2431, 2463, 2495, 2527, 2559,
  2591, 2623, 2655, 2687, 2719, 2751, 2783, 2815,
  2847, 2879, 2911, 2943, 2975, 3007, 3039, 3071,
  3103, 3135, 3167, 3199, 3231, 3263, 3295, 3327,
  3359, 3391, 3423, 3455, 3487, 3519, 3551, 3583,
  3615, 3647, 3679, 3711, 3743, 3775, 3807, 3839,
  3871, 3903, 3935, 3967, 3999, 4031, 4063, 4095,
  4063, 4031, 3999, 3967, 3935, 3903, 3871, 3839,
  3807, 3775, 3743, 3711, 3679, 3647, 3615, 3583,
  3551, 3519, 3487, 3455, 3423, 3391, 3359, 3327,
  3295, 3263, 3231, 3199, 3167, 3135, 3103, 3071,
  3039, 3007, 2975, 2943, 2911, 2879, 2847, 2815,
  2783, 2751, 2719, 2687, 2655, 2623, 2591, 2559,
  2527, 2495, 2463, 2431, 2399, 2367, 2335, 2303,
  2271, 2239, 2207, 2175, 2143, 2111, 2079, 2048,
  2016, 1984, 1952, 1920, 1888, 1856, 1824, 1792,
  1760, 1728, 1696, 1664, 1632, 1600, 1568, 1536,
  1504, 1472, 1440, 1408, 1376, 1344, 1312, 1280,
  1248, 1216, 1184, 1152, 1120, 1088, 1056, 1024,
  992, 960, 928, 896, 864, 832, 800, 768,
  736, 704, 672, 640, 608, 576, 544, 512,
  480, 448, 416, 384, 352, 320, 288, 256,
  224, 192, 160, 128, 96, 64, 32, 0
};

/////////////////////sine lookup///////////////////////

const PROGMEM uint16_t Lookup_Sine[256] =
{
  2048, 2098, 2148, 2198, 2248, 2298, 2348, 2398,
  2447, 2496, 2545, 2594, 2642, 2690, 2737, 2784,
  2831, 2877, 2923, 2968, 3013, 3057, 3100, 3143,
  3185, 3226, 3267, 3307, 3346, 3385, 3423, 3459,
  3495, 3530, 3565, 3598, 3630, 3662, 3692, 3722,
  3750, 3777, 3804, 3829, 3853, 3876, 3898, 3919,
  3939, 3958, 3975, 3992, 4007, 4021, 4034, 4045,
  4056, 4065, 4073, 4080, 4085, 4089, 4093, 4094,
  4095, 4094, 4093, 4089, 4085, 4080, 4073, 4065,
  4056, 4045, 4034, 4021, 4007, 3992, 3975, 3958,
  3939, 3919, 3898, 3876, 3853, 3829, 3804, 3777,
  3750, 3722, 3692, 3662, 3630, 3598, 3565, 3530,
  3495, 3459, 3423, 3385, 3346, 3307, 3267, 3226,
  3185, 3143, 3100, 3057, 3013, 2968, 2923, 2877,
  2831, 2784, 2737, 2690, 2642, 2594, 2545, 2496,
  2447, 2398, 2348, 2298, 2248, 2198, 2148, 2098,
  2048, 1997, 1947, 1897, 1847, 1797, 1747, 1697,
  1648, 1599, 1550, 1501, 1453, 1405, 1358, 1311,
  1264, 1218, 1172, 1127, 1082, 1038,  995,  952,
  910,  869,  828,  788,  749,  710,  672,  636,
  600,  565,  530,  497,  465,  433,  403,  373,
  345,  318,  291,  266,  242,  219,  197,  176,
  156,  137,  120,  103,   88,   74,   61,   50,
  39,   30,   22,   15,   10,    6,    2,    1,
  0,    1,    2,    6,   10,   15,   22,   30,
  39,   50,   61,   74,   88,  103,  120,  137,
  156,  176,  197,  219,  242,  266,  291,  318,
  345,  373,  403,  433,  465,  497,  530,  565,
  600,  636,  672,  710,  749,  788,  828,  869,
  910,  952,  995, 1038, 1082, 1127, 1172, 1218,
  1264, 1311, 1358, 1405, 1453, 1501, 1550, 1599,
  1648, 1697, 1747, 1797, 1847, 1897, 1947, 1997
};

///////////////////////////////////////////////////////

int cmd = 0;
int scmd = 0;


void setup()
{
  Serial.begin(9600); // initialize serial communication @9600 baud rate
  dac.begin(0x62);//the begin I2C communication Gy 4725 which has a address of 0x62
  pinMode(A0, INPUT); // initialize pin A0 as input for voltmeter
  pinMode(2, OUTPUT); // initialize pin 2 as output for motor
  pinMode(3, OUTPUT); // initialize pin 3 as output for motor
}

void loop()
{
  main:
  cmd = Serial.read(); // read recieved data from the serial port and save it in cmd

  ///////////////////////voltmeter/////////////////////////////

  byte val = map(analogRead(A0), 0, 1024.0, 0, 255);
  // map the 10 bit valve of ADC to 8 bit for transmitting as a single byte
  Serial.write(val);//write 8 bit value to the serial port
 
  ///////////////////////motor control/////////////////////////

  if (cmd == '0')
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
  }
  else if (cmd == '1')
  {
    digitalWrite(2, LOW);
    digitalWrite(3, HIGH);
  }
  else if (cmd == '2')
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
  }

  ////////////////////Function generator/////////////////////////

  if (cmd == '3')
  {
  sine:
    uint16_t counter;
    for (counter = 0; counter < 256; counter++)
    {
      dac.setVoltage(pgm_read_word(&(Lookup_Sine[counter])), false);
    }

    scmd = Serial.read();
    if (scmd == '6')
    {
      goto main;
    }
    else if (scmd == '4')
    {
      goto triangle;
    }
    else if (scmd == '5')
    {
      goto square;
    }
    else
    {
      goto sine;
    }
  }

  if (cmd == '4')
  {
triangle:
    uint16_t counter;
    for (counter = 0; counter < 256; counter++)
    {
      dac.setVoltage(pgm_read_word(&(Lookup_tri[counter])), false);
    }

    scmd = Serial.read();
    if (scmd == '6')
    {
      goto main;
    }
    else if (scmd == '3')
    {
      goto sine;
    }
    else if (scmd == '5')
    {
      goto square;
    }
    else
    {
      goto triangle;
    }
  }

  if (cmd == '5')
  {
square:
    uint16_t counter;
    for (counter = 0; counter < 128; counter++)
    {
      dac.setVoltage(pgm_read_word(1), false);
    }
    for (counter = 128; counter < 256; counter++)
    {
      dac.setVoltage(0, false);
    }

    scmd = Serial.read();
    if (scmd == '6')
    {
      goto main;
    }
    else if (scmd == '3')
    {
      goto sine;
    }
    else if (scmd == '4')
    {
      goto triangle;
    }
    else
    {
      goto square;
    }
  }
  delay(100);
}

Own IOT website and Hardware Using Node MCU (cyber thinks)

NODE MCU code -- website link  Cyberthinks google drive link  cyberthinks website files #include <ESP8266WiFi.h> #include <ArduinoJ...