Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1.  
  2. #include <Wire.h>
  3. #include <Adafruit_MCP4725.h>
  4.  
  5. Adafruit_MCP4725 dac;
  6.  
  7. #define DAC_RESOLUTION (9)
  8.  
  9. const int buttonPin = 2; // the number of the pushbutton pin
  10. int buttonState; // the current reading from the input pin
  11. int lastButtonState = LOW; // the previous reading from the input pin
  12.  
  13.  
  14. unsigned long lastDebounceTime = 0;
  15. unsigned long debounceDelay = 50;
  16.  
  17.  
  18. const PROGMEM uint16_t Table[512] =
  19. {
  20. 939, 945, 946, 947, 951, 956,
  21. 962, 967, 973, 978, 983, 989, 994, 1000, 1005, 1015,
  22. 1024, 1034, 1043, 1053, 1062, 1075, 1087, 1100, 1112, 1121,
  23. 1126, 1131, 1136, 1141, 1146, 1151, 1156, 1164, 1172, 1179,
  24. 1187, 1194, 1202, 1209, 1216, 1222, 1229, 1235, 1241, 1248,
  25. 1254, 1260, 1264, 1268, 1271, 1275, 1279, 1283, 1287, 1286,
  26. 1284, 1281, 1279, 1276, 1274, 1271, 1268, 1266, 1263, 1261,
  27. 1258, 1256, 1253, 1251, 1246, 1242, 1237, 1232, 1227, 1222,
  28. 1218, 1215, 1211, 1207, 1203, 1199, 1195, 1191, 1184, 1178,
  29. 1171, 1165, 1159, 1152, 1146, 1141, 1136, 1130, 1125, 1120,
  30. 1115, 1110, 1103, 1096, 1088, 1080, 1073, 1065, 1057, 1049,
  31. 1040, 1030, 1021, 1012, 1004, 995, 987, 982, 978, 974,
  32. 970, 966, 963, 959, 955, 952, 949, 945, 942, 939,
  33. 938, 939, 940, 941, 943, 944, 945, 946, 946, 946,
  34. 946, 946, 946, 946, 946, 947, 950, 952, 954, 956,
  35. 958, 960, 962, 964, 965, 965, 965, 965, 965, 965,
  36. 963, 960, 957, 954, 951, 947, 944, 941, 938, 932,
  37. 926, 920, 913, 907, 901, 894, 885, 865, 820, 733,
  38. 606, 555, 507, 632, 697, 752, 807, 896, 977, 1023,
  39. 1069, 1127, 1237, 1347, 1457, 2085, 2246, 2474, 2549, 2595,
  40. 2641, 2695, 3083, 3135, 3187, 3217, 3315, 3403, 3492, 3581,
  41. 3804, 3847, 3890, 3798, 3443, 3453, 3297, 3053, 2819, 2810,
  42. 2225, 2258, 1892, 1734, 1625, 998, 903, 355, 376, 203,
  43. 30, 33, 61, 90, 119, 160, 238, 275, 292, 309,
  44. 325, 343, 371, 399, 429, 484, 542, 602, 652, 703,
  45. 758, 802, 838, 856, 875, 895, 917, 938, 967, 1016,
  46. 1035, 1041, 1047, 1054, 1060, 1066, 1066, 1064, 1061, 1058,
  47. 1056, 1053, 1051, 1048, 1046, 1043, 1041, 1038, 1035, 1033,
  48. 1030, 1028, 1025, 1022, 1019, 1017, 1014, 1011, 1008, 1006,
  49. 1003, 1001, 999, 998, 996, 994, 993, 991, 990, 988,
  50. 986, 985, 983, 981, 978, 976, 973, 971, 968, 966,
  51. 963, 963, 963, 963, 963, 963, 963, 963, 963, 963,
  52. 963, 963, 963, 963, 963, 963, 963, 963, 963, 963,
  53. 964, 965, 966, 967, 968, 969, 970, 971, 972, 974,
  54. 976, 978, 980, 989, 991, 993, 995,
  55. 997, 999, 1002, 1006, 1011, 1015, 1019, 1023, 1028, 1032,
  56. 1036, 1040, 1045, 1050, 1055, 1059, 1064, 1069, 1076, 1082,
  57. 1088, 1095, 1101, 1107, 1114, 1120, 1126, 1132, 1141, 1149,
  58. 1158, 1166, 1173, 1178, 1183, 1188, 1193, 1198, 1203, 1208,
  59. 1214, 1221, 1246, 1250, 1254, 1259, 1263,
  60. 1269, 1278, 1286, 1294, 1303, 1309, 1315, 1322, 1328, 1334,
  61. 1341, 1343, 1353, 1355, 1357, 1359,
  62. 1359, 1359, 1359, 1359, 1358, 1356, 1354, 1352, 1350, 1347,
  63. 1345, 1343, 1341, 1327, 1324,
  64. 1322, 1320, 1317, 1315, 1312, 1307, 1301, 1294, 1288, 1281,
  65. 1275, 1270, 1265, 1260, 1256, 1251, 1246, 1240, 1233, 1227,
  66. 1221, 1214, 1208, 1201, 1194, 1186, 1178, 1170, 1162, 1154,
  67. 1148, 1144, 1140, 1136, 1131, 1127, 1123, 1118, 1114, 1107,
  68. 1099, 1090, 1082, 1074, 1069, 1064, 1058, 1053, 1048, 1043,
  69. 1038, 1034, 1029, 1025, 1021, 1017, 1013, 1009, 1005, 1001,
  70. 997, 994, 990, 991, 992, 994, 996, 997, 999, 998,
  71. 997, 996, 995, 994, 993, 991, 990, 989, 989, 989,
  72. 989, 988, 986, 984, 983, 981, 980, 1002,
  73. 1005, 1008, 1012
  74. };
  75.  
  76.  
  77. void setup(void) {
  78. Serial.begin(9600);
  79. dac.begin(0x62);
  80. pinMode(buttonPin, INPUT);
  81. Serial.println("Generating a pulse");
  82. }
  83.  
  84. void RunSignal(){
  85. Serial.println("Worked");
  86. uint16_t i;
  87.  
  88. #if DAC_RESOLUTION == 9
  89. for (i = 0; i < 512; i++)
  90. {
  91. dac.setVoltage(pgm_read_word(&(Table[i])), false);
  92. }
  93. #endif
  94. }
  95.  
  96.  
  97.  
  98. void loop(void) {
  99. int reading = digitalRead(buttonPin);
  100.  
  101. if (reading != lastButtonState) {
  102. lastDebounceTime = millis();
  103. }
  104.  
  105. if ((millis() - lastDebounceTime) > debounceDelay) {
  106.  
  107.  
  108. if (reading != buttonState) {
  109. buttonState = reading;
  110.  
  111. if (buttonState == HIGH) {
  112. RunSignal();
  113. }
  114. }
  115.  
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement