Pages: [1]   Go Down
Author Topic: binary form in Serial window  (Read 409 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all,


i am using the following code DAC from
 



Code:
int led = 31;

//1kHz
int sine[] = {2048,2305,2557,2802,3034,3251,3449,3625,3777,3901,3995,4059,4092,4092,4060,3996,3902,3778,3628,3452,3254,3037,2805,2560,2308,2051,1795,1542,1297,1065,847,649,473,321,197,102,37,4,4,35,99,193,316,466,642,839,1056,1288,1533,1785,2041};

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);   
  pinMode(DAC0, OUTPUT);   
}

// the loop routine runs over and over again forever:
void loop() {
  for(int i = 0; i<50;i++){
      if(sine[i]>4095) {
         sine[i]=4095;
         digitalWrite(led, LOW);
     }
    analogWriteResolution(12);
    analogWrite(DAC0, sine[i]);
    delayMicroseconds(14);
  }
}

i want to see the binary form of the sine wave in Serial window. i know there is print() function but i am not sure how to use it.

any help would be greatly appreciated,

m,
Logged

Laguna Hills, CA 92653
Offline Offline
Full Member
***
Karma: 0
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps...
Code:

Serial.println(sine[i], HEX) ; // or DEC

in the loop, in the for-I, maybe just print the first
time through the Loop to avoid printing too much?

Serial.begin(115200) ;
in the setup
« Last Edit: December 05, 2013, 08:40:04 am by garygid » Logged

Cheers, Gary
Due for controlling Electric car charging.
Nissan LEAF - Mini Quick Charge (mQC)

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks i will try it,

regards,

m
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


hi

i've tried this function but it gives me HEX. not binary

Serial.println(sine, HEX) ; // or DEC



regards,

M
Logged

The Netherlands
Offline Offline
Full Member
***
Karma: 1
Posts: 139
MKDS hacker and Programmer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use BIN instead of HEX.
Logged

Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

Pages: [1]   Go Up
Jump to: