Показать сообщение отдельно
Старый 26.02.2019, 20:31   #6
belui
Старший Пользователь
 
Регистрация: 17.02.2014
Возраст: 39
Регион: 26
Сообщений: 138
belui is a glorious beacon of lightbelui is a glorious beacon of lightbelui is a glorious beacon of lightbelui is a glorious beacon of lightbelui is a glorious beacon of light
По умолчанию

На этом форуме, стр.3 есть видео где человек реализовал перемотку зажатием перемотки. Его код.



Там же есть человек который выложил содержимое скетча в котором присутствуют строки интересующие меня (я так думаю). Пропишите их куда нужно

Его код:

Код:
int PINO = 8;            // Digital IO pin connected to base of transistor
int Length = 537;        // Length in Microseconds
int DebugOn = 0;

#define POWERNOFF 0x00
#define VOLUP 0x04
#define VOLDOWN 0x05
#define MUTE 0x06
#define SOURCE 0x08
#define EQUALIZER 0x0d///0x0C
#define MUTE2 0x0e//0x0D// - Mute/Unmute (and Power OFF with "press and hold" - see below)
#define SEARCHFORW 0x12// - Seach + / Track + (and Manual Tune + / Fast fwd with "press and hold")
#define SEARCHBACK 0x13// - Seach - / Track - (and Manual Tune - / Fast rwd with "press and hold")
#define BANDFORW 0x14// - Band cycle / Folder + //programs
#define BANDBACK 0x15// - Band cycle / Folder + //programs
#define PROGR 0x15// - Program 1-6 cycle / Folder -//programs
//#define UNKNOWN 0x16// - Sel cycle (it cycles between Fader/Balance/Loudness/Subwoofer out level/Volume gain for the current source)

#define GREENPIN 5
#define BLUEPIN 3
#define YELLOWPIN 6
#define BROWNPIN 7
#define REDPIN 4
#define BLACKPIN 2

#define OUT_PINS 3
unsigned char out_pins[OUT_PINS]={
  GREENPIN,BLUEPIN,YELLOWPIN};

void setup() {
  pinMode(PINO, OUTPUT);
  digitalWrite(PINO, LOW); // Make PIN low to shut off transistor
  Serial.begin(115200);
  Serial.println("Enter 1 to Go");
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  pinMode(YELLOWPIN, OUTPUT);
  pinMode(BROWNPIN, INPUT_PULLUP);
  pinMode(REDPIN, INPUT_PULLUP);
  pinMode(BLACKPIN, INPUT_PULLUP);
}

unsigned char GetJoystic(void){
  static unsigned char stage = 0;
  static unsigned char scroll_stored;
  unsigned char tmp,i;
  if (++stage > (OUT_PINS-1)) stage=0;

  for (i=0;i<(OUT_PINS);i++)
    if (i==stage){
      digitalWrite(out_pins[i], LOW);
    }
  else{
    digitalWrite(out_pins[i], HIGH);
  }

  delay(10);

  tmp = digitalRead(BROWNPIN);
  if (!tmp){
    if (stage != scroll_stored){
      char scrl = stage-scroll_stored;
      scroll_stored = stage;
      if ((scrl == 1) ||(scrl==-2)) {
        Serial.println("Scroll-");
        return SEARCHFORW;
      }else{
        Serial.println("Scroll+");
        return SEARCHBACK;
      }
    }
  }
  tmp = digitalRead(REDPIN);
  if (!tmp){
    switch(stage){
    case 0:
      Serial.println("Select");
      return SOURCE;
    case 1:
      Serial.println("Vol+");
      return VOLUP;
    case 2:
      Serial.println("Vol-");
      return VOLDOWN;
    }
  }
  tmp = digitalRead(BLACKPIN);
  if (!tmp){
    switch(stage){
    case 0:
      Serial.println("Source-");
      return BANDFORW;
    case 1:
      Serial.println("Mute");
      return MUTE2;
    case 2:
      Serial.println("Source+");
      return BANDBACK;
    }
  }
  return 0;
}

void loop() {
  unsigned char Key = GetJoystic();
  static unsigned char code = 0;
  if (Key){
    Serial.print("Key    Serial.println(Key,HEX);
    JVCSendCommand(Key);
    delay(2);
    JVCSendCommand(Key);
    delay(20);
  }

  if (Serial.available() > 0) {
    char inp=Serial.read();
    Serial.print("Received
    Serial.println(inp, DEC);
    switch (inp){
      case '1':
      code--;
      break;
      case '2':
      code++;
      break;
      case '3':
      JVCSendCommand(code);
      break;
    }
  
  
  }
}  // end of loop


void JVCSendCode(unsigned char code){
  unsigned char i,tmp=1;
  for (i=0;i<sizeof(code)*8-1;i++){//7bits
    if (code & tmp)
      bONE();
    else
      bZERO();
    tmp = tmp << 1;
  }
}

void JVCSendCommand(unsigned char code){
  Preamble();
  JVCSendCode((unsigned char)code);
  Postamble();
}

//    Wire signals to be generated for a '1' bit
void bONE() {                     // Send a binary ONE over the line
  if (DebugOn == 1) {
    Serial.print(" 1 ");
  }
  digitalWrite(PINO, HIGH);        // Pull 3.5mm TIP low
  delayMicroseconds(Length);      // for 537us
  digitalWrite(PINO, LOW);         // Allow 3.5mm TIP to go high
  delayMicroseconds(Length * 3);  // for 537 * 3 = 1611us
}

//    Wire signals to be generated for a '0' bit
void bZERO() {   // Send a binary ZERO over the line
  if (DebugOn == 1) {
    Serial.print(" 0 ");
  }
  digitalWrite(PINO, HIGH);        // Pull 3.5mm TIP low
  delayMicroseconds(Length);      // for 537us
  digitalWrite(PINO, LOW);         // Allow 3.5mm TIP to go high
  delayMicroseconds(Length);      // for 537us
}

//    Wire signals to be generated for a start of signal to a JVC
void Preamble() {
  if (DebugOn == 1) {
    Serial.println(" ");
    Serial.print(" AGC ");
  }
  digitalWrite(PINO, LOW);         // Not sure what this does
  delayMicroseconds(Length * 1);

  digitalWrite(PINO, HIGH);        // AGC
  delayMicroseconds(Length * 16);

  digitalWrite(PINO, LOW);         // AGC
  delayMicroseconds(Length * 8);

  bONE();    // 1 Start Bit
  JVCSendCode(0x47);
}

//    Wire signals to be generated for a end of signal  
void Postamble() {
  if (DebugOn == 1) {
    Serial.print(" STOP ");
  }
  bONE();
  bONE();    // 2 stop bits
}
P.S. This JVC has not 3.5mm jack inpu


А это содержимое скетча который я выкладывал в первом сообщении:

Код:
#include "Arduino.h"
#include "SoftwareSerial.h"


// Define commands
#define POWERNOFF   0x0A
#define VOLUP       0x04
#define VOLDOWN     0x05
#define SOURCE      0x08
#define EQUALIZER   0x0D
#define MUTE        0x0E
#define NEXTTRACK   0x12
#define PREVTRACK   0x13
#define FOLDERFORW  0x14
#define FOLDERBACK  0x15

//Define outputs
#define VOLUP_PIN    2 // D2
#define VOLDOWN_PIN     3 // D3
#define NEXTTRACK_PIN      5 // D4
#define PREVTRACK_PIN    4 // D5
#define SOURCE_PIN   6 // D6
#define SCROLLUP_PIN    9 // B1
#define SCROLLDOWN_PIN    10 // B2

// Connect optocoupler input through a 1k resistor to this pin
#define OUTPUTPIN   8 // D8

// On-board LED, useful for debugging
#define LEDPIN     13 // D13

// Pulse width in µs
#define PULSEWIDTH 555

// Address that the radio responds to
#define ADDRESS 0x47//47

unsigned long currentTime, holdbutton;
unsigned long loopTime;
int PrevState = 0;

void setup() 
{
  
    currentTime = millis();    
    loopTime = currentTime; 
    pinMode(OUTPUTPIN, OUTPUT);    // Set the proper pin as output
    digitalWrite(OUTPUTPIN, LOW);  // Output LOW to make sure optocoupler is off
  
    // Set the pins connected to the steering wheel remote as input / output
    pinMode(VOLUP_PIN, INPUT_PULLUP);
    pinMode(VOLDOWN_PIN, INPUT_PULLUP);
    pinMode(NEXTTRACK_PIN, INPUT_PULLUP);
    pinMode(PREVTRACK_PIN, INPUT_PULLUP);
    pinMode(SOURCE_PIN, INPUT_PULLUP);
    pinMode(SCROLLUP_PIN, INPUT_PULLUP);
    pinMode(SCROLLDOWN_PIN, INPUT_PULLUP);
      
    pinMode(LEDPIN, OUTPUT);                  // Set pin connected to on-board LED as output...
    digitalWrite(LEDPIN, LOW);     

    digitalWrite(LEDPIN, HIGH); 
    delay(1000);
    digitalWrite(LEDPIN, LOW); 
    // ...and turn LED off
}

unsigned char GetInput(void) 
{

  currentTime = millis();
  
    if(currentTime >= (loopTime + 10))
    {
      
          //VOLUP
          if(PrevState == VOLUP_PIN && digitalRead(VOLUP_PIN))
          {
            PrevState = 0;
            return VOLUP;   
          }
          else if (PrevState == VOLUP_PIN && currentTime >= (holdbutton + 500))
          {
              holdbutton = currentTime;
              return VOLUP;
          }
          else if(PrevState == 0 && !digitalRead(VOLUP_PIN))
          {
            holdbutton = currentTime;
            PrevState = VOLUP_PIN; 
          }
    
          //VOLDOWN
          if(PrevState == VOLDOWN_PIN && digitalRead(VOLDOWN_PIN))
          {
            PrevState = 0;
            return VOLDOWN;
          }
          else if (PrevState == VOLDOWN_PIN && currentTime >= (holdbutton + 500))
          {
              holdbutton = currentTime;
              return VOLDOWN;
          }
          else if(PrevState == 0 && !digitalRead(VOLDOWN_PIN))
          {
            holdbutton = currentTime;
            PrevState = VOLDOWN_PIN; 
          }    
    
          //NEXTTRACK
          if(PrevState == NEXTTRACK_PIN && digitalRead(NEXTTRACK_PIN))
          {
            PrevState = 0;
            return NEXTTRACK;
            }
          else if(PrevState == 0 && !digitalRead(NEXTTRACK_PIN))
          {
            PrevState = NEXTTRACK_PIN; 
          }  
    
          //PREVTRACK
          if(PrevState == PREVTRACK_PIN && digitalRead(PREVTRACK_PIN))
          {
            PrevState = 0;
            return PREVTRACK;
            }
          else if(PrevState == 0 && !digitalRead(PREVTRACK_PIN))
          {
            PrevState = PREVTRACK_PIN; 
          }  


          //SOURCE - PAUSE(LONG PUSH 1sec)
          if((PrevState == SOURCE_PIN && digitalRead(SOURCE_PIN)) || (PrevState == POWERNOFF && digitalRead(SOURCE_PIN)))
          {
            if(PrevState == SOURCE_PIN)
            {
               PrevState = 0;
              return SOURCE;
            }
            else if (PrevState == POWERNOFF)
            {
              PrevState = 0;
              return 0;
            }
          }
          else if(PrevState == 0 && !digitalRead(SOURCE_PIN))
          {
            holdbutton = currentTime;
            PrevState = SOURCE_PIN; 
          }  
          //PAUSE(LONG PUSH 1sec)
          if(PrevState == SOURCE_PIN && currentTime >= (holdbutton + 1000))
          {
              PrevState = POWERNOFF;
              return MUTE;
          }

            
          //SCROLLUP_PIN
          if(PrevState == SCROLLUP_PIN && digitalRead(SCROLLUP_PIN))
          {
             PrevState = 0;
             if(digitalRead(SCROLLDOWN_PIN))
             {
                return FOLDERFORW;
             }
             else
            {
                return FOLDERBACK;              
            }
             
          }
          else if(PrevState == 0 && !digitalRead(SCROLLUP_PIN))
          {
                PrevState = SCROLLUP_PIN; 
          }  
          loopTime = currentTime;  // Updates loopTime
      }
      return 0;
}

void loop() 
{
 unsigned char Key = GetInput(); 
  if (Key) 
  { 
     SendCommand(Key);
      delay(2);
      SendCommand(Key);
      delay(20);   
  }
}

// Send a value (7 bits, LSB is sent first, value can be an address or command)
void SendValue(unsigned char value) {
  unsigned char i, tmp = 1;
  for (i = 0; i < sizeof(value) * 8 - 1; i++) {
    if (value & tmp)  // Do a bitwise AND on the value and tmp
      SendOne();
    else
      SendZero();
    tmp = tmp << 1; // Bitshift left by 1
  }
}

// Send a command to the radio, including the header, start bit, address and stop bits
void SendCommand(unsigned char value) {
  unsigned char i;
  Preamble();       
  for (i = 0; i < 1; i++) {           // Repeat address, command and stop bits three times so radio will pick them up properly
    SendValue(ADDRESS);               // Send the address
    SendValue((unsigned char)value);  // Send the command
    Postamble();                      // Send signals to follow a command to the radio
  }
}

// Signals to transmit a '0' bit
void SendZero() {
  digitalWrite(OUTPUTPIN, HIGH);      // Output HIGH for 1 pulse width
  digitalWrite(LEDPIN, HIGH);         // Turn on on-board LED
  delayMicroseconds(PULSEWIDTH);
  digitalWrite(OUTPUTPIN, LOW);       // Output LOW for 1 pulse width
  digitalWrite(LEDPIN, LOW);          // Turn off on-board LED
  delayMicroseconds(PULSEWIDTH);
}

// Signals to transmit a '1' bit
void SendOne() {
  digitalWrite(OUTPUTPIN, HIGH);      // Output HIGH for 1 pulse width
  digitalWrite(LEDPIN, HIGH);         // Turn on on-board LED
  delayMicroseconds(PULSEWIDTH);
  digitalWrite(OUTPUTPIN, LOW);       // Output LOW for 3 pulse widths
  digitalWrite(LEDPIN, LOW);          // Turn off on-board LED
  delayMicroseconds(PULSEWIDTH * 3);
}

// Signals to precede a command to the radio
void Preamble() {
  // HEADER: always LOW (1 pulse width), HIGH (16 pulse widths), LOW (8 pulse widths)
  digitalWrite(OUTPUTPIN, LOW);       // Make sure output is LOW for 1 pulse width, so the header starts with a rising edge
  digitalWrite(LEDPIN, LOW);          // Turn off on-board LED
  delayMicroseconds(PULSEWIDTH * 1);
  digitalWrite(OUTPUTPIN, HIGH);      // Start of header, output HIGH for 16 pulse widths
  digitalWrite(LEDPIN, HIGH);         // Turn on on-board LED
  delayMicroseconds(PULSEWIDTH * 16);
  digitalWrite(OUTPUTPIN, LOW);       // Second part of header, output LOW 8 pulse widths
  digitalWrite(LEDPIN, LOW);          // Turn off on-board LED
  delayMicroseconds(PULSEWIDTH * 8);
  
  // START BIT: always 1
  SendOne();
}

// Signals to follow a command to the radio
void Postamble() {
  // STOP BITS: always 1
  SendOne();
  SendOne();
}
belui вне форума   Ответить с цитированием