chipKIT® Development Platform

Inspired by Arduino™

How do I get all 10 bits from A)

Created Mon, 08 Jul 2013 04:01:16 +0000 by apruszen


apruszen

Mon, 08 Jul 2013 04:01:16 +0000

I tried this modified code no joy Tony P */ #include <stdio.h>

int sensorPin = A0; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the A int ledPin2 = 43; // other board led int Ebit9 = 34; // Bit 9 of PORTE int Ebit10 =35; // Bit 10 of PORTE int Ebit8 = 33;
int Ebit7 = 32;
int Ebit6 = 31;
int Ebit5 = 30;
int Ebit4 = 29;
int Ebit3 = 28;
int Ebit2 = 27;
int Ebit1 = 26; // Bit 1 of PORTE (LSB)

void setup() { // declare the ledpins and PORTE bits 9&10 as an OUTPUTS: pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(Ebit9, OUTPUT);
pinMode(Ebit10, OUTPUT); pinMode(Ebit8, OUTPUT); pinMode(Ebit7, OUTPUT); pinMode(Ebit6, OUTPUT); pinMode(Ebit5, OUTPUT); pinMode(Ebit4, OUTPUT); pinMode(Ebit3, OUTPUT); pinMode(Ebit2, OUTPUT); pinMode(Ebit1, OUTPUT); // LSB for PORTE

ledPin = 0; // Set all Pins to 0 ledPin2 = 0; Ebit1 = 0; //LSB of 10 Bit Value Ebit2 = 0; Ebit3 = 0; Ebit4 = 0; Ebit5 = 0; Ebit6 = 0; Ebit7 = 0; Ebit8 = 0; Ebit9 = 0; Ebit10 = 0; //MSB of 10 Bit value

}

void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin);
// turn the ledPin on ledPin2 off PORTE = sensorValue;

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin, HIGH);

           /* This turns the LEDS on for th corresponding bit of the analogue value
  Ebit1 = bitRead(sensorValue,1);
  Ebit2 = bitRead(sensorValue,2);
  Ebit3 = bitRead(sensorValue,3);
  Ebit4 = bitRead(sensorValue,4);
  Ebit5 = bitRead(sensorValue,5);
  Ebit6 = bitRead(sensorValue,6);
  Ebit7 = bitRead(sensorValue,7);
  Ebit8 = bitRead(sensorValue,8);     
  Ebit9 = bitRead(sensorValue,9);
  Ebit10   = bitRead(sensorValue,10);      

*/

Ebit9 = 0; // stop the program for <sensorValue> milliseconds: delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, HIGH);
// stop the program for for < > milliseconds: delay(10);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);

// stop the program for for <sensorValue> milliseconds: delay(500);


Ian_B

Mon, 08 Jul 2013 17:20:38 +0000

So it looks like your problem is coming from trying to assign different values to the pins you are using. In your code, you have:

ledPin = 0; // Set all Pins to 0 ledPin2 = 0; Ebit1 = 0; //LSB of 10 Bit Value Ebit2 = 0; Ebit3 = 0; Ebit4 = 0; Ebit5 = 0; Ebit6 = 0; Ebit7 = 0; Ebit8 = 0; Ebit9 = 0; Ebit10 = 0; //MSB of 10 Bit value

It looks like you are trying to change the values on the pins, but you are actually changing the pin number of all your variables to pin 0. When you are trying to set the value on all pins to zero, try using this format:

digitalWrite(ledPin, LOW);

Generally you don't want to change your pin numbers in your code, so when you declare pins at the beginning of your code, you can try defining each of the pin values or declare them as constants. You'll have to adjust the rest of your code too once you do this.

//Defining pins: #define ledPin 13

//Declaring pins as constants: const int ledPin = 13;


majenko

Mon, 08 Jul 2013 20:31:42 +0000

Also note that your 10 bits of data are numbered 0 to 9, not 1 to 10, so you should be using bitRead(sensorValue, 0) ... bitRead(sensorValue, 9) instead.