Show Posts
Pages: [1] 2 3 ... 17
1  Using Arduino / Programming Questions / Re: getting specific bits from bytes.How? on: July 19, 2013, 01:38:00 am
is this code correct?

That depends. What is it supposed to do?

i have explain whay i want to do. to get the bits from the array variables temp[] and store them to variable export
2  Using Arduino / Programming Questions / Re: getting specific bits from bytes.How? on: July 18, 2013, 04:27:35 pm
hmm.

Code:
void loop() {
    byte temp[8];
    byte export_val;
    temp[0]=B10000000;
    temp[1]=B00100000;
    temp[2]=B00000000;
    temp[3]=B00010000;
    temp[4]=B10000100;
    temp[5]=B01001100;
    temp[6]=B10000011;
    temp[7]=B01000111;
    
    
    for (int i=0;i<8;i++){
        bitWrite(export_val,i,bitRead(temp[i],i));
    }
}

is this code correct?
3  Using Arduino / Programming Questions / Re: getting specific bits from bytes.How? on: July 18, 2013, 04:09:46 pm
Quote
how can i merge them then to export variables?
Define what "merge" and "export" mean to you.

with bitread i will get bits from bytes. how can i convert bits to byte? (this is what i call merge)

export is the variable that bits stored to
4  Using Arduino / Programming Questions / Re: getting specific bits from bytes.How? on: July 18, 2013, 03:59:55 pm
Do yourself a favour and make the temp variable an array.  Then you can iterate through the array and bits using a single for loop to read the bits in temp and set the bits in the export variable.

ok lets suppose temp[8] is the array

with bitread i will read the bits and store them to a variable. how can i merge them then to export variables?

in my project i  have a big display
i have an inport variable array [144] and an export variable array [144].
actually i want to change the bits from import variables "fix" them and transfer them to export variables corrected and the "print" to the display.


 
5  Using Arduino / Programming Questions / getting specific bits from bytes.How? on: July 18, 2013, 03:40:54 pm
Hi.
How can get some bits from a bytes?

example:
byte export;
byte temp_0=B10000000;
byte temp_1=B00100000;
byte temp_2=B00000000;
byte temp_3=B00010000;
byte temp_4=B10000100;
byte temp_5=B01001100;
byte temp_6=B10000011;
byte temp_7=B01000111;

I want the export variable to have the first bit from temp_0, the second bit from temp_1,the third bit from temp_2 ...until temp_7
so the export must have the value B10010111
6  Using Arduino / Programming Questions / Re: start code from the begining .How? on: May 06, 2013, 04:41:41 pm
there is a function that checks if there is "OFF" signal from IR remote control (lets name this function IR_CHECK). if user presses off button then it stores "1" to a temp variables. if user press  "ON" button it stores "0" to that temp variable

on my project there are many other functions (displaying graphic efe,showing scrolling text and other)
all these functions are calling IR_CHECK function to check if there is "OFF" or "ON" signal. and they works like this:

if (temp==0){
  task_0();
  task_1();
  task_2();
 //...
 //...
}
if (temp==1){
  task_temperature();//show only temperature
}

so when user presses OFF button the only fanction that runs is task_temperature. the only problem is that it needs to wait to finish the current task (some of them are spending some seconds)
7  Using Arduino / Programming Questions / Re: start code from the begining .How? on: May 06, 2013, 04:10:50 pm
well this is what i have made using arduino code:


the code is really complicated and big. user can program it via IR remote control.

each loop takes about 1-3 minutes. I want the add a new feauture now. "night mode"
when user presses "off" button on remote control, the cross display need to show only temperature. (this is night mode).
i succed to do that with a flag, but the functions are spending a lot of time and it needs to finish one of them and then go to night mode.
for example when it scrolling the time, when user presses "off" button it waits to finish this fuction (maybe about 5-10 seconds) and then it goes to night mode.. and this is not what i want from that. i want to turning on night mode in real time


edit.

i found this
void(* resetFunc) (void) = 0; //declare reset function @ address 0
...
resetFunc();  //call reset

is it safe to use it?
8  Using Arduino / Programming Questions / Re: start code from the begining .How? on: May 06, 2013, 03:23:32 pm
yes. function
9  Using Arduino / Programming Questions / Re: start code from the begining .How? on: May 06, 2013, 03:08:06 pm
you are right. my original scetch is really big so i decided to give you an example on what i want to do.

so check again my code.
it runs many task and in all these tasks it checks for IR.
all i need is to start from begining when a IR signal is coming
10  Using Arduino / Programming Questions / start code from the begining .How? on: May 06, 2013, 02:52:45 pm
I have a program that makes some tasks and it checks for infrared signals.

all i want is every time it checks for IR signals i want the scetch to start from begining. I tried with goto but it only works inside their void

Code:
byte incoming_IR_data;
void setup() {                

  pinMode(13, OUTPUT);    
}

void loop() {
  start:
  task_0();
  task_1();
  task_2(); 
}

void task_0(){
  
  //some code here
   check_IR();
}
void task_1(){
  
  //some code here
   check_IR();
}
void task_2(){
  
  //some code here
   check_IR();
}
void check_IR(){
 //Some code that checks IR and stores data from Infrared to incoming_IR_data variable
 
     if (incoming_IR_data==12524){
       goto start;  
     }
  
  
}
11  Using Arduino / Programming Questions / Re: Help On reading SD card like EEPROM on: February 07, 2013, 05:21:41 pm
i need to store many data that arduino will read and store them to variables arrays. data are integers with values 0-255.

how could i do that with files?
12  Using Arduino / Programming Questions / Help On reading SD card like EEPROM on: February 07, 2013, 04:56:28 pm
Hi. i need big storage and SD card is more than enough for me.

But i need to be able to read/write on address like an eeprom.
So i dont want to use files. Only read/write bytes on any address of that.

Is it posible to do that? and if yes how?
also i would like to know about the speed of SD cards. Are they faster than eeprom?
13  Using Arduino / Programming Questions / Re: Communication with 2 x DS18B20 on: January 09, 2013, 01:25:04 pm
forgot to mention that i have no problem with any other code (just to be sure is not buggy, some codes doesnt gives negative values)
14  Using Arduino / Programming Questions / Communication with 2 x DS18B20 on: January 09, 2013, 01:03:59 pm
Hi i have 2 DS18B20 sensors and i want to recieve temperature values from both sensors. (one by one)
Each DS18B20 is connected to different pin. (for example pin 10 and pin 11).
How could i do that on code please??

here is the code i am using


Code:
#include <OneWire.h>

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library

OneWire  ds(10);  // on pin 10

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
 
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
 
  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
 
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
 
  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // convert the data to actual temperature

  unsigned int raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // count remain gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
    // default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
}
15  Using Arduino / Programming Questions / Re: declare 1 pin on 2 names on: July 11, 2012, 01:45:22 pm
actually i created my own PCB board with PIC32MX795F512 with many components (FRAM,RAM,EEPROM) and i have common pins on some components (CY62148EV30,DS1744W)
i am using arduino code so i prefer to not have common names (variables) on both components. It will be easier to program them
Pages: [1] 2 3 ... 17