1
Dependencies: DebugLibrary MCP4xxxx_SPI mbed
Fork of MCP41xxxApp by
main.cpp
00001 #include <string> 00002 #include <iostream> 00003 #include <iomanip> 00004 #include <mbed.h> 00005 #include <math.h> 00006 /** 00007 * Tests were done with schema proposed here: DS11195C-page 11 FIGURE 2-25: Potentiometer Divider Non-Linearity Error Test Circuit (DNL, INL) 00008 */ 00009 #include "MCP4xxxx_SPI.h" 00010 00011 struct UserChoice { 00012 char choice; 00013 unsigned char moduleId; 00014 }; 00015 00016 /* 00017 * Declare functions 00018 */ 00019 void AvailableIndicator(); // LED1 flashing for program while program is alive 00020 UserChoice DisplayMenuAndGetChoice(); // Display and get the user choice 00021 00022 /* 00023 * Declare statics 00024 */ 00025 00026 DigitalOut chipSelect[] = {p8,p9,p10}; // c - MAIS SIGNIFICATIVO 00027 00028 00029 00030 CMCP4xxxx_SPI g_digitalPot(p5, p6, p7, NC, NC, NC); // Create an instance of the class CMCP4xxxx_SPI, p5/p6/p7: SPI#1, /CS managed by library, /RESET input not connected, , /SHDN input not connected 00031 00032 int main() { 00033 00034 //unsigned int potLevel1 = 0x0; // Initial digital potentiometer value 00035 //unsigned int potLevel2 = 0x0; // Initial digital potentiometer value 00036 00037 int value = 0; 00038 int num_pot = 0; 00039 00040 while (true) 00041 { 00042 do { 00043 00044 printf("\r\nDigite o numero do potenciometro (1 a 8):"); 00045 scanf("%d", &num_pot); 00046 }while(num_pot < 1 || num_pot > 12); 00047 00048 do { 00049 00050 printf("\r\nDigite o valor do volume (0 a 8):"); 00051 scanf("%d", &value); 00052 }while(value < 0 || value >255); 00053 00054 00055 00056 chipSelect[0].write(((num_pot-1) >> 2) & 0x1); 00057 chipSelect[1].write(((num_pot-1) >> 1) & 0x1); 00058 chipSelect[2].write(((num_pot-1) >> 0) & 0x1); 00059 00060 int value2 = 256 - (pow((double)2,(double)value)); 00061 printf("Value = %d", value2); 00062 00063 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot1, value2); 00064 00065 00066 00067 chipSelect[0].write(1); 00068 chipSelect[1].write(1); 00069 chipSelect[2].write(1); 00070 /* 00071 00072 g_chipSelect1.write(0); 00073 00074 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot1, potLevel1); 00075 00076 00077 g_chipSelect1.write(1); 00078 00079 00080 g_chipSelect2.write(0); 00081 00082 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot1, potLevel2); 00083 00084 00085 g_chipSelect2.write(1); 00086 00087 potLevel1+=1; 00088 potLevel2-=1; 00089 00090 g_chipSelect2.write(0); 00091 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot1, potLevel2); 00092 g_chipSelect2.write(1);*/ 00093 00094 } 00095 00096 00097 } 00098 00099
Generated on Tue Jul 19 2022 08:18:42 by
1.7.2

